guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: guile-user Digest, Vol 188, Issue 9


From: Zelphir Kaltstahl
Subject: Re: guile-user Digest, Vol 188, Issue 9
Date: Mon, 9 Jul 2018 08:24:16 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0


On 09.07.2018 05:42, Keith Wright wrote:
> Actually my copy of the manual says:
>   (predicate func)
>     ...
>      then getopt-long will apply func to the value,
>      and throw an exception if it returns #f.
>
>     func should be a procedure which accepts a string and
>     returns a boolean value; you may need to use
>     quasiquotes to get it intoa grammar.
>
> So a warning about quasiquote _is_ mentioned in the Guile docs,
> although it wouldn't hurt to put in an example to clarify just _how_
> to "use quasiquote to get it into the grammmar."
>
>> There seems to be no reason for it to force me
>> to do that, except that it does not work otherwise.
> When I first read that, I was exasperated.  What more reason
> do you need to do it right?  It works that way and doesn't
> work if you do it wrong.
>
> Upon further reflection I realized that you are probably not
> asking why right is better than wrong, but confused about
> what quasiquote does.
>
> The manual says:
>   func should be a procedure
>
> You said:
>>>> I am providing a function that takes the
>>>> option's value as string and returns #t or #f.
> but that is _not_ what you were doing.  If the whole
> list is quoted, then the occurrence of "string-exact-integer?"
> in the list is a _symbol_.  It must be unquoted so
> that it will be evaluated to a function (i.e. procedure).
>
> It's like the difference between (+ 2 2) and ('+ 2 2).
>
> The manual could use more explanation, but I believe
> it is correct.
>
> Hope this helps.
>
>   -- Keith

Haha, yes, I was talking about my confusion with the quasiquote :D Maybe
I should have put that a little clearer.

About the phrase in the docs: That's interesting. I was thinking when I
read your reply: "Wha...? How could I overlook that? I read multiple
times!" and it turns out, that we have different versions of the same docs!

For me it reads:

> Finally, the |predicate| property can be used to constrain the
possible values of an option. If used, the |predicate| property should
be set to a procedure that takes one argument — the proposed option
value as a string — and returns either |#t| or |#f| according as the
proposed value is or is not acceptable. If the predicate procedure
returns |#f|, |getopt-long| will signal an error.

on
https://www.gnu.org/software/guile/manual/html_node/Option-Specification.html#Option-Specification

Am I reading an old version or a different page?

Anyway, now that you explain it like this, I suddenly understand why it
was wrong not to use quasiquote + unquote. In my code it was used as a
symbol, because of the quote. Unquoting would then do what I thought I
was doing. However, it still seems like it could be able to figure out
what predicate I am specifying from that symbol, couldn't it? Something
like "find the function for this symbol"? But then again I specified a
lambda before I tried a named function/predicate and then it could not
have gotten, that I guess.
I might also try to use (list …), if it is possible to avoid quote and
with that non-evaluation. But I guess it is not, because of other
undefined things in the specification of the options.

Thanks for helping me getting rid of the confusion!

~ Zelphir


reply via email to

[Prev in Thread] Current Thread [Next in Thread]