* Backquote simplification @ 2010-12-09 11:00 Hans Aberg [not found] ` <CCCBC725-4AE9-4585-B18D-7DF6650D5880@mac.com> 0 siblings, 1 reply; 8+ messages in thread From: Hans Aberg @ 2010-12-09 11:00 UTC (permalink / raw) To: guile-user Is it possible to simplify the backquote construct `(,x_1 ... ,x_k) (always unquote on all arguments) somehow, so that the unquote does not need to appear multiple times (depending on k)? (I construct these in the C-interface, and it would simplify not having to remove a sequence of them.) Specifically, in (define g (lambda (x . y) `(,x . ,y))) then evaluations like (g 1 2 3), (g 1 2 . (3 4)) work. So I would want something like (define g (lambda (x . y) (b x . y)))) where (b x . y) might be any expression where the unquote does not need to appear on every variable. Only combinations line (define g (lambda (x . y) (b `(,x . ,y)))) seem to work. Hans ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <CCCBC725-4AE9-4585-B18D-7DF6650D5880@mac.com>]
* Re: Backquote simplification [not found] ` <CCCBC725-4AE9-4585-B18D-7DF6650D5880@mac.com> @ 2010-12-09 19:44 ` Hans Aberg 2010-12-10 23:12 ` Neil Jerram 0 siblings, 1 reply; 8+ messages in thread From: Hans Aberg @ 2010-12-09 19:44 UTC (permalink / raw) To: dskr; +Cc: guile-user [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) ...)) Then (lambda (x1 ... xk . y) (f x1 ... xk y)) should just return at least k arguments as a list. I'm not sure right now how to write it, so thankful for help. On 9 Dec 2010, at 18:44, dskr@mac.com wrote: > Hi, > > You need not use quoting at all in these cases. > > ( 1 2 . ( 3 4 ) ) is exactly equivalent to ( 1 2 3 4 ) and ( 1 . > ( 2 . ( 3 . ( 4 ) ) ) ) > > (b ( cons x y )) > or > (apply b x y) > > I cannot quite tell fom your example. > > Cheers, > Dan ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Backquote simplification 2010-12-09 19:44 ` Hans Aberg @ 2010-12-10 23:12 ` Neil Jerram 2010-12-11 0:03 ` Hans Aberg 0 siblings, 1 reply; 8+ messages in thread From: Neil Jerram @ 2010-12-10 23:12 UTC (permalink / raw) To: Hans Aberg; +Cc: guile-user Hans Aberg <haberg-1@telia.com> writes: > [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. Neil ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Backquote simplification 2010-12-10 23:12 ` Neil Jerram @ 2010-12-11 0:03 ` Hans Aberg 2010-12-11 0:25 ` Neil Jerram 0 siblings, 1 reply; 8+ messages in thread From: Hans Aberg @ 2010-12-11 0:03 UTC (permalink / raw) To: Neil Jerram; +Cc: guile-user 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. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Backquote simplification 2010-12-11 0:03 ` Hans Aberg @ 2010-12-11 0:25 ` Neil Jerram 2010-12-11 8:33 ` Hans Aberg 0 siblings, 1 reply; 8+ messages in thread From: Neil Jerram @ 2010-12-11 0:25 UTC (permalink / raw) To: Hans Aberg; +Cc: guile-user Hans Aberg <haberg-1@telia.com> writes: > 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)) > )) OK, I roughly see that this solves your problem of wanting to unquote an arbitrary number of list elements. (Although I don't understand why you need to do that.) > It behaves as I want in my context, a functional language on top of > Guile. Scheme is already a functional language, isn't it? > I decided to implement the construct (lambda (x_1 ... x_k . y) > f) What syntax is that expression in? In Scheme syntax, it's a lambda that returns a value that is apparently unrelated to any of the arguments, and so could equally well be written as (lambda ignored-args 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))) How is this different from (define f (lambda args args)) ? > 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. As Dan pointed out, that is not an improper list. It's a proper list. In the hope that these questions might be useful to at least one of us... Neil ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Backquote simplification 2010-12-11 0:25 ` Neil Jerram @ 2010-12-11 8:33 ` Hans Aberg 2010-12-11 10:01 ` Neil Jerram 0 siblings, 1 reply; 8+ messages in thread From: Hans Aberg @ 2010-12-11 8:33 UTC (permalink / raw) To: Neil Jerram; +Cc: guile-user On 11 Dec 2010, at 01:25, Neil Jerram wrote: >> 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)) >> )) > > OK, I roughly see that this solves your problem of wanting to > unquote an > arbitrary number of list elements. (Although I don't understand why > you > need to do that.) One reason is that in the normal syntax f(x_1, ..., x_k) there are two separate parts f and (x_1, ..., x_k) that are combined, whereas in Scheme it is combined to one (f x_1 ... x_k) and does not have a concept for the (x_1, ..., x_k). Another is that it is needed in the translation of expressions like f(g(x)) --> (f (g x)), and (f g)x --> ((f g) x). >> It behaves as I want in my context, a functional language on top of >> Guile. > > Scheme is already a functional language, isn't it? I am using Bison/Flex parser/lexer to generate a different syntax. It turns out to be a good help not having to implement the back-end. >> I decided to implement the construct (lambda (x_1 ... x_k . y) >> f) > > What syntax is that expression in? In Scheme syntax, it's a lambda > that > returns a value that is apparently unrelated to any of the arguments, > and so could equally well be written as (lambda ignored-args f). I implement it using Guile C calls, and when constructing using scm_list_3(scm_sym_lambda, x, f), it turns out that x = (x_1 ... x_k . y) is an improper list. >> 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))) > > How is this different from > > (define f (lambda args args)) > > ? The form (x_1 ... x_k . y) is an improper list that requires at least k arguments, and the rest given arguments are put into y as a list. >> 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. > > As Dan pointed out, that is not an improper list. It's a proper list. That would be true if the evaluator does not try to evaluate the expression before the substitution of y. That works in the case of a freestanding (g x_1 ... x_k . y), but for some reason not in the form (lambda (x_1 ... x_k . y) (g x_1 ... x_k . y)) I do not know why. > In the hope that these questions might be useful to at least one of > us... I do not know what that means. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Backquote simplification 2010-12-11 8:33 ` Hans Aberg @ 2010-12-11 10:01 ` Neil Jerram 2010-12-11 10:09 ` Hans Aberg 0 siblings, 1 reply; 8+ messages in thread From: Neil Jerram @ 2010-12-11 10:01 UTC (permalink / raw) To: Hans Aberg; +Cc: guile-user Hi Hans, To reply quickly to one point in your email... (I'll ponder the rest later.) Hans Aberg <haberg-1@telia.com> writes: > On 11 Dec 2010, at 01:25, Neil Jerram wrote: > >> In the hope that these questions might be useful to at least one of >> us... > > I do not know what that means. I meant that I'm sure I don't understand yet what you're doing, and hence that the answers might help me; and that there was a possibility that you might not be understanding some things, and that in that case the discussion might help you too. Regards, Neil ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Backquote simplification 2010-12-11 10:01 ` Neil Jerram @ 2010-12-11 10:09 ` Hans Aberg 0 siblings, 0 replies; 8+ messages in thread From: Hans Aberg @ 2010-12-11 10:09 UTC (permalink / raw) To: Neil Jerram; +Cc: guile-user On 11 Dec 2010, at 11:01, Neil Jerram wrote: > To reply quickly to one point in your email... (I'll ponder the rest > later.) Whenever you so want. >>> In the hope that these questions might be useful to at least one of >>> us... >> >> I do not know what that means. > > I meant that I'm sure I don't understand yet what you're doing, and > hence that the answers might help me; and that there was a possibility > that you might not be understanding some things, and that in that case > the discussion might help you too. Yes, the replies are helpful, though I am programming also directly with Guile C calls involving unevaluated expressions. ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-12-11 10:09 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-12-09 11:00 Backquote simplification Hans Aberg [not found] ` <CCCBC725-4AE9-4585-B18D-7DF6650D5880@mac.com> 2010-12-09 19:44 ` Hans Aberg 2010-12-10 23:12 ` Neil Jerram 2010-12-11 0:03 ` Hans Aberg 2010-12-11 0:25 ` Neil Jerram 2010-12-11 8:33 ` Hans Aberg 2010-12-11 10:01 ` Neil Jerram 2010-12-11 10:09 ` Hans Aberg
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).