Re: Ann: URI quasiquotes library

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 07/09/2013 12:17 PM, Michael Hendricks wrote:
> On Mon, Jul 8, 2013 at 9:56 AM, Jan Wielemaker <[email protected]

> I agree that functional notation is convenient.  The packs library(func)
> <http://www.swi-prolog.org/pack/list?p=func> and
> library(function_expansion)
> <http://www.swi-prolog.org/pack/list?p=function_expansion> are two of my
> favorites.

There is a long history of functional notation libraries in Prolog:
your two, GRIPS (by Jocelyn Paine), Ciao, are just a few I'm aware of.
Would be nice if the Prolog community could come to some form of
agreement here :-(

>     However, this functional notation need not be readable for
>     the user.  Possibly we should introduce a functional notation
>     library that does not affect normal Prolog syntax, but can be
>     enabled by default.  Something like '$EVAL'(Term).
>
>
> How do you imagine '$EVAL'(Term) behaving?  What kind of Term values are
> allowed?  One of the most common patterns I use with
> library(function_expansion) is to treat this:
>
>      foo('$EVAL'(Term))
>
> as if the code were this:
>
>      call(Term, Output),
>      foo(Output)
>
> Is that what you have in mind?

Yes.  For every goal, find the embedded '$EVAL'(Term),
and insert goals before it that evaluate them.  Quasi
quotations seem to come in some forms:

   - Those that describe a goal.  For example, {|sql||Query|}
     can expand into a call to odbc_query/3.
   - Those that describe data that is intended for a specific
     predicate.  Here, we can simply insert the qq into the
     proper argument location and the predicate can be designed
     to deal with the QQ result term.
   - Those that describe more or less generic data structures
     that can be passed to many predicates.  Your uri example
     is one of them.  You want to think about {|uri||...|} as
     an atom/string, but in fact it produces something that
     must be processed before it creates an atom/string at
     runtime.  You would like to be able to hide this processing
     from the user.  Else you need to write this, which removes
     most of the fun.

	expand_uri({|uri||....|}, Var),
	something(Var),
	...

So, for qq we can get away with a functional notation that uses
an unlikely and verbose term because it only needs to be entered
once when defining the QQ.

	Cheers --- Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.