Cecil Westerhof <
Ce...@decebal.nl> wrote:
> Rich <ri...@example.invalid> writes:
>
>> Cecil Westerhof <
Ce...@decebal.nl> wrote:
>>> Rich <ri...@example.invalid> writes:
>>>
>>>> Cecil Westerhof <
Ce...@decebal.nl> wrote:
>>>>> I have a function to fetch all fonts. But this can of-course only be
>>>>> called if Tk is loaded. Is there a way to verify that a package (in
>>>>> this case Tk) is loaded?
>>>>>
>>>>> I do not want to use:
>>>>> package require Tk
>>>>>
>>>>> Because that creates a window if Tk was not loaded.
>>>>
>>>> "man package"
>>>
>>> Sadly the man pages are not installed on my system.
>>
>> I would highly recommend you install the man pages. That is unless
>> your 'system' is windows, then installing them likely won't work at
>> all.
>
> I was planning to do that. I wanted to ask on the Debian list how to
> do it. I find it a bit strange because of all other packages the man
> pages are installed. But it was very easy: I just had to install
> tcl-doc.
Ah, yes, Debian, with their silly split of X, X-dev, and X-doc
packages.
One of the many reasons why I run Slackware. Slackware is sensible.
When you install X, you get all of X, X-dev, and X-doc all at once. No
silliness.
>> Care to elaborate on "does not work"?
>
> I should have evaluate further. :'-(
>
> For one thing, if I enter:
> expr ![catch {package present Tk}]
Why in the world would your first 'test' be to run it inside a catch,
and run that inside an expr?
If you are running from a REPL, start by /just running the bare
command/:
$ rlwrap tclsh
% package present Tk
package Tk is not present
%
Your catch hid the return value string from 'package present' and only
returned to you "1", which the ! then flipped to "0", which expr
evaluated as false (and since 'false' from expr returns nothing, a prompt
is reasonable there).
> I get a secondary prompt.
No, you should have been returned to the main prompt:
% expr ![catch {package present Tk}]
0
%
The 'secondary' prompt looks different (empty, unless you've changed your
local defaults):
% expr {1+1
> When I define the function in the interactive shell and call it, I
> would expect to get False (or 0), but I get:
> in
> while evaluating {is_Tk_present }
Again, why did you start out with a complex monster in the REPL first.
It is best to build up from the basic building blocks one block at a
time, then you see what happens at each step:
$ rlwrap tclsh
% package present Tk
package Tk is not present
% catch {package present Tk} r
1
% set r
package Tk is not present
% expr ![catch {package present Tk} r]
0
% set r
package Tk is not present
%
And using rlwrap (since Tcl's default REPL has not history) is 'really
useful' because it adds full readline history/editing around commands
that don't offer the same themselves.
As for your 'in', since you failed to "show your work" for
"is_Tk_present", and I *can't read your mind over usenet*, I can only
speculate as to what went wrong.