guile-user
[Top][All Lists]
Advanced

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

Re: Backquote simplification


From: Hans Aberg
Subject: Re: Backquote simplification
Date: Sat, 11 Dec 2010 01:03:48 +0100

On 11 Dec 2010, at 00:12, Neil Jerram wrote:

[Your reply does not seem to be on the list, so I cc it.]

Thanks. I might try an iterated cons, that is a function f such such
that
 (f x1 ... xk y) --> (cons x1 ... (cons xk y) ...))

Isn't that just `list'?

More generally: I've been reading your emails, but I'm afraid I have no idea what you are trying to do. Perhaps you could step back and explain
that overall, before continuing with details.

The reply I got was helpful, but I decided to settle for a macro implementation:

(use-syntax (ice-9 syncase))

(define-syntax tuple
  (syntax-rules ()
    ((tuple xs ...)
     `(tuple ,xs ...))
    ((tuple x1 x2 . y)
     (append `(tuple ,x1 ,x2) y))
    ((tuple x1 . y)
     (append `(tuple ,x1) y))
))

It behaves as I want in my context, a functional language on top of Guile. I decided to implement the construct (lambda (x_1 ... x_k . y) f) using an improper list (x_1 ... x_k . y); when it is a proper list, one just gets the fixed number of arguments construct.

Then the object (x_1 ... x_k . y) also become available, so it is possible to form
  (define f (lambda (x_1 ... x_k . y) (x_1 ... x_k . y)))
Then one would expect f(a_1, ..., a_n), for n >= k, to be (a_1, ..., a_n) - this a form of the identity.

So to get this effect, I need a function g that can call improper lists (g x_1, ..., x_k . y), where y is a list. For some reason, the substitution of the list y to get a list for the function g does not work in this situation, exception for the macro definition above, g = tuple.

Then, there is another problem with this macro: if having the ".", one cannot have "...", like would be needed say when implementing (define (f x_1 ... x_k . y) ...) expanding to (define f (lambda (x_1 ... x_k . y) ...) for any k. That is, the following isn't legal:

(define-syntax tuple
  (syntax-rules ()
    ((tuple xs ...)
     `(tuple ,xs ...))
    ((tuple xs ... . y)
     `(tuple ,xs ... . ,y))
))

But if it would have been, it would produce what I want.




reply via email to

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