* List functions @ 2010-12-01 16:28 Hans Aberg 2010-12-01 17:35 ` Joel James Adamson ` (2 more replies) 0 siblings, 3 replies; 17+ messages in thread From: Hans Aberg @ 2010-12-01 16:28 UTC (permalink / raw) To: guile-user I am writing on a parser that translates normal function syntax in to Guile code. It seems natural to translate (f, g) x into ((f g) x), and () x into (() x), but I'm not sure if the lists (f g) and () can be made acting as functions this way. So what would be natural here? (Constants might be made evaluating to themselves, for example (5 x_1 ...) -> 5.) Hans ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 16:28 List functions Hans Aberg @ 2010-12-01 17:35 ` Joel James Adamson 2010-12-01 17:48 ` Hans Aberg 2010-12-01 19:51 ` Andy Wingo 2010-12-02 9:57 ` Marco Maggi 2 siblings, 1 reply; 17+ messages in thread From: Joel James Adamson @ 2010-12-01 17:35 UTC (permalink / raw) To: Hans Aberg; +Cc: guile-user [-- Attachment #1: Type: text/plain, Size: 601 bytes --] Hans Aberg <haberg-1@telia.com> writes: > It seems natural to translate (f, g) x into ((f g) x), and () x into > (() x), but I'm not sure if the lists (f g) and () can be made acting > as functions this way. (f g) would evaluate as a composition as long as f takes a procedure as an argument and returns a function that takes x as its argument. No problems there. Alternatively you could think of f returning a function of x when it evaluates g. Joel -- Joel J. Adamson Servedio Lab University of North Carolina at Chapel Hill FSF Member #8164 http://www.unc.edu/~adamsonj [-- Attachment #2: Type: application/pgp-signature, Size: 229 bytes --] ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 17:35 ` Joel James Adamson @ 2010-12-01 17:48 ` Hans Aberg 2010-12-01 19:20 ` Keith Wright 0 siblings, 1 reply; 17+ messages in thread From: Hans Aberg @ 2010-12-01 17:48 UTC (permalink / raw) To: Joel James Adamson; +Cc: guile-user On 1 Dec 2010, at 18:35, Joel James Adamson wrote: >> It seems natural to translate (f, g) x into ((f g) x), and () x into >> (() x), but I'm not sure if the lists (f g) and () can be made acting >> as functions this way. > > (f g) would evaluate as a composition as long as f takes a procedure > as > an argument and returns a function that takes x as its argument. No > problems there. Alternatively you could think of f returning a > function > of x when it evaluates g. Yes, but in standard syntax would be natural to let (f, g)(x) evaluate to (f(x), g(x)), producing a list of two elements. In Guile, that would be something involving "map". If I try in Haskell, I can let (sin, cos)(2) be the same as map (g 2) [sin, cos] where g x = \f -> f x -> [0.909297426825682,-0.416146836547142] But when I try that similar constructs in Guile, I get problems with evaluation. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 17:48 ` Hans Aberg @ 2010-12-01 19:20 ` Keith Wright 2010-12-01 19:50 ` Hans Aberg 0 siblings, 1 reply; 17+ messages in thread From: Keith Wright @ 2010-12-01 19:20 UTC (permalink / raw) To: haberg-1; +Cc: guile-user > From: Hans Aberg <haberg-1@telia.com> > Cc: guile-user@gnu.org > > On 1 Dec 2010, at 18:35, Joel James Adamson wrote: > > >> I am writing on a parser that translates normal > >> function syntax in to Guile code. > >> > >> It seems natural to translate (f, g) x into ((f g) x), If "(f, g) x" is (in normal syntax) supposed to mean: apply f to g resulting in a function that is applied to x, then that is "natural", but whether that is normal syntax, I can not say. I'm liberal on this. Normal syntax is whatever you want, but step one is to get clear on what you want. Speaking for myself, I have never before seen that syntax with that meaning, so I would hesitatate to call it "normal". But if you define it, you can call it what you will. > >> and () x into (() x), but I'm not sure if the > >> lists (f g) and () can be made acting as functions > >> this way. I have not only never seen the "normal syntax" in use here, but I have no guess what it is supposed to mean. In Scheme "(() x)" means nothing at all. In fact it is so far from meaningful that I can not guess how to fix it. > > (f g) would evaluate as a composition as long as > > f takes a procedure as an argument and returns a > > function that takes x as its argument. No problems > > there. Alternatively you could think of f > > returning a function of x when it evaluates g. This is wrong terminology. The expression (f g) applies f to g. The composition of f and g is (lambda (x) (f (g x))). > Yes, but in standard syntax would be natural to let (f, g)(x) evaluate > to (f(x), g(x)), producing a list of two elements. In Guile, that > would be something involving "map". If I try in Haskell, I can let > (sin, cos)(2) be the same as > map (g 2) [sin, cos] where g x = \f -> f x > -> [0.909297426825682,-0.416146836547142] > But when I try that similar constructs in Guile, I get problems with > evaluation. Works for me guile> (let () (define (g x)(lambda (f)(f x))) (map (g 2) (list sin cos))) (0.909297426825682 -0.416146836547142) There are other ways to write it, but that is the most direct translation of your Haskell into Scheme. -- Keith ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 19:20 ` Keith Wright @ 2010-12-01 19:50 ` Hans Aberg 2010-12-01 20:26 ` Hans Aberg 2010-12-01 21:34 ` Keith Wright 0 siblings, 2 replies; 17+ messages in thread From: Hans Aberg @ 2010-12-01 19:50 UTC (permalink / raw) To: Keith Wright; +Cc: guile-user On 1 Dec 2010, at 20:20, Keith Wright wrote: >> ... in standard syntax would be natural to let (f, g)(x) evaluate >> to (f(x), g(x)), producing a list of two elements. In Guile, that >> would be something involving "map". If I try in Haskell, I can let >> (sin, cos)(2) be the same as >> map (g 2) [sin, cos] where g x = \f -> f x >> -> [0.909297426825682,-0.416146836547142] >> But when I try that similar constructs in Guile, I get problems with >> evaluation. > > Works for me > > guile> (let () > (define (g x)(lambda (f)(f x))) > (map (g 2) (list sin cos))) > > (0.909297426825682 -0.416146836547142) > > There are other ways to write it, but that > is the most direct translation of your Haskell > into Scheme. I was trying variations like (let () (define (g x)(lambda (f)(f x))) (map (g 2) '(sin cos))) Which gives an error: In expression (f x): Wrong type to apply: sin I'm not sure when to use quote or list, here. Quote seems to work when the list is data, not a list of functions. >>>> I am writing on a parser that translates normal >>>> function syntax in to Guile code. >>>> >>>> It seems natural to translate (f, g) x into ((f g) x), > > If "(f, g) x" is (in normal syntax) supposed to mean: > > apply f to g resulting in a function that is applied to x, > > then that is "natural", but whether that is normal > syntax, I can not say. I'm liberal on this. > Normal syntax is whatever you want, but step > one is to get clear on what you want. > > Speaking for myself, I have never before seen that > syntax with that meaning, so I would hesitatate > to call it "normal". But if you define it, you can > call it what you will. This normality only has to do with parser grammar implementation. If in the evaluation syntax f ..., and the binding syntax corresponding in Haskell to \ ... -> f, the two "..." use the same syntax, I can eliminate the "\". Then the evaluation syntax (f_1, ..., f_k) x becomes available. I could eliminate it semnatically or set it to what is common in math, if not too complicated. >>>> and () x into (() x), but I'm not sure if the >>>> lists (f g) and () can be made acting as functions >>>> this way. > > I have not only never seen the "normal syntax" in > use here, but I have no guess what it is supposed > to mean. In Scheme "(() x)" means nothing at all. > In fact it is so far from meaningful that I can > not guess how to fix it. One can set the constants to functions that evaluate to themselves. One use would be expressions like (1 + f)(x). The () just shows up in the context above. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 19:50 ` Hans Aberg @ 2010-12-01 20:26 ` Hans Aberg 2010-12-01 21:34 ` Keith Wright 1 sibling, 0 replies; 17+ messages in thread From: Hans Aberg @ 2010-12-01 20:26 UTC (permalink / raw) To: Keith Wright; +Cc: guile-user On 1 Dec 2010, at 20:50, Hans Aberg wrote: >>> ... in standard syntax would be natural to let (f, g)(x) evaluate >>> to (f(x), g(x)), producing a list of two elements. In Guile, that >>> would be something involving "map". If I try in Haskell, I can let >>> (sin, cos)(2) be the same as >>> map (g 2) [sin, cos] where g x = \f -> f x >>> -> [0.909297426825682,-0.416146836547142] >>> But when I try that similar constructs in Guile, I get problems with >>> evaluation. >> >> Works for me >> >> guile> (let () >> (define (g x)(lambda (f)(f x))) >> (map (g 2) (list sin cos))) >> >> (0.909297426825682 -0.416146836547142) >> >> There are other ways to write it, but that >> is the most direct translation of your Haskell >> into Scheme. > > I was trying variations like > (let () > (define (g x)(lambda (f)(f x))) > (map (g 2) '(sin cos))) > Which gives an error: > In expression (f x): > Wrong type to apply: sin > > I'm not sure when to use quote or list, here. Quote seems to work > when the list is data, not a list of functions. I realized the problem here: quote prevents evaluation in the list, so one gets symbols, not procedures. Using back-quote and comma works: (let () (define (g x)(lambda (f)(f x))) (map (g 2) `(,sin ,cos))) Anyway, thanks, I now know what to fiddle around with. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 19:50 ` Hans Aberg 2010-12-01 20:26 ` Hans Aberg @ 2010-12-01 21:34 ` Keith Wright 2010-12-01 22:19 ` Hans Aberg ` (2 more replies) 1 sibling, 3 replies; 17+ messages in thread From: Keith Wright @ 2010-12-01 21:34 UTC (permalink / raw) To: haberg-1; +Cc: guile-user > Cc: adamsonj@email.unc.edu, guile-user@gnu.org > From: Hans Aberg <haberg-1@telia.com> > > I was trying variations like > (let () > (define (g x)(lambda (f)(f x))) > (map (g 2) '(sin cos))) > Which gives an error: > In expression (f x): > Wrong type to apply: sin Somebody should patch that so that it mentions the wrong type. it means first argument of apply should be a function but it is: sin, which is a symbol > I'm not sure when to use quote or list, here. > Quote seems to work when the list is data, > not a list of functions. It's the other way around; |quote| is a keyword that means that the following is data. If you want to make a list of anything other than literal data, use |list|. So '(sin cos) is data: a list of two symbols, the same as (list 'sin 'cos). On the other hand |list| is an ordinary variable so, (list sin cos) is evaluated by evaluating the three subexpressions, giving a function that makes lists and two numeric functions of a numeric vaiable, and then applying the first function, i.e. list, to the two arguments, ie. sin and cos, giving a list of functions. > This normality only has to do with parser grammar > implementation. If in the evaluation syntax f ..., > and the binding syntax corresponding in Haskell to > \... -> f, the two "..." use the same syntax, I can > eliminate the "\". Then the evaluation syntax (f_1, > ..., f_k) x becomes available. I could eliminate it > semnatically or set it to what is common in math, if > not too complicated. > > >>>> and () x into (() x), but I'm not sure if the > >>>> lists (f g) and () can be made acting as functions > >>>> this way. > > > > I have not only never seen the "normal syntax" in > > use here, but I have no guess what it is supposed > > to mean. In Scheme "(() x)" means nothing at all. > > In fact it is so far from meaningful that I can > > not guess how to fix it. > > One can set the constants to functions that evaluate > to themselves. One use would be expressions like > (1 + f)(x). The () just shows up in the context above. I didn't really follow that, but in seems that you want to be able to apply a list of functions to a single argument, and get a list of the results of applying each function separately to the same argument. guile> (define (fmap fs x) (if (null? fs) '() (cons (apply (car fs) (list x)) (fmap (cdr fs) x) ))) guile> (fmap (list sin cos) 2) (0.909297426825682 -0.416146836547142) The only tricky part is that apply takes a function and a list of arguments, and so (list x) is a list of one argument. -- Keith ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 21:34 ` Keith Wright @ 2010-12-01 22:19 ` Hans Aberg 2010-12-01 22:43 ` Hans Aberg 2010-12-03 15:06 ` Hans Aberg 2 siblings, 0 replies; 17+ messages in thread From: Hans Aberg @ 2010-12-01 22:19 UTC (permalink / raw) To: Keith Wright; +Cc: guile-user On 1 Dec 2010, at 22:34, Keith Wright wrote: > On the other hand |list| is an ordinary variable > so, (list sin cos) is evaluated by evaluating > the three subexpressions, giving a function > that makes lists and two numeric functions of > a numeric vaiable, and then applying the first > function, i.e. list, to the two arguments, ie. > sin and cos, giving a list of functions. The parse problem I have is that x y is function application x(y), and must be constructed as Guile (x y). But then what should (x, y) be constructed as? Here, x should never be applied to y. On the other hand, '(x y) will suspend evaluation of x an y, which should not happen. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 21:34 ` Keith Wright 2010-12-01 22:19 ` Hans Aberg @ 2010-12-01 22:43 ` Hans Aberg 2010-12-03 15:06 ` Hans Aberg 2 siblings, 0 replies; 17+ messages in thread From: Hans Aberg @ 2010-12-01 22:43 UTC (permalink / raw) To: guile-user On 1 Dec 2010, at 22:34, Keith Wright wrote: >> I was trying variations like >> (let () >> (define (g x)(lambda (f)(f x))) >> (map (g 2) '(sin cos))) >> Which gives an error: >> In expression (f x): >> Wrong type to apply: sin > > Somebody should patch that so that it mentions the > wrong type. it means > > first argument of apply should be a function > but it is: sin, which is a symbol Yes, I realized this. >> I'm not sure when to use quote or list, here. >> Quote seems to work when the list is data, >> not a list of functions. > > It's the other way around; |quote| is a keyword > that means that the following is data. > If you want to make a list of anything other > than literal data, use |list|. > > So '(sin cos) is data: a list of two symbols, > the same as (list 'sin 'cos). Strictly speaking, they are, as you noted, symbols. Quote turns off further evaluation. If one should have a more normal evaluation model of tuples, perhaps one should use back-quote and commas (see below). > On the other hand |list| is an ordinary variable > so, (list sin cos) is evaluated by evaluating > the three subexpressions, giving a function > that makes lists and two numeric functions of > a numeric vaiable, and then applying the first > function, i.e. list, to the two arguments, ie. > sin and cos, giving a list of functions. I build lists directly using the Guile C functions. However, I encountered an ambiguity in my implementation which has to do with the (x) = x property of tuples: both x y and (x, y) parsed as Guile (x y) = (list x y). If one writes just (x_1, ..., x_k), what Guile object should one get? (x_1 ... x_k) may cause later evaluation, '(x_1 ... x_k) turns off evaluation of the arguments. So perhaps one should construct `(,x_1 ... ,x_k). >> This normality only has to do with parser grammar >> implementation. If in the evaluation syntax f ..., >> and the binding syntax corresponding in Haskell to >> \... -> f, the two "..." use the same syntax, I can >> eliminate the "\". Then the evaluation syntax (f_1, >> ..., f_k) x becomes available. I could eliminate it >> semnatically or set it to what is common in math, if >> not too complicated. >> >>>>>> and () x into (() x), but I'm not sure if the >>>>>> lists (f g) and () can be made acting as functions >>>>>> this way. >>> >>> I have not only never seen the "normal syntax" in >>> use here, but I have no guess what it is supposed >>> to mean. In Scheme "(() x)" means nothing at all. >>> In fact it is so far from meaningful that I can >>> not guess how to fix it. >> >> One can set the constants to functions that evaluate >> to themselves. One use would be expressions like >> (1 + f)(x). The () just shows up in the context above. > > I didn't really follow that, but in seems that > you want to be able to apply a list of functions > to a single argument, and get a list of the > results of applying each function separately > to the same argument. Yes, and the first item of the list should not treat the following items as its arguments for an evaluation. It is a different data object than the Guile evaluation list. > guile> > (define (fmap fs x) > (if (null? fs) > '() > (cons (apply (car fs) (list x)) > (fmap (cdr fs) x) ))) > > guile> (fmap (list sin cos) 2) > (0.909297426825682 -0.416146836547142) > > The only tricky part is that apply takes > a function and a list of arguments, > and so (list x) is a list of one argument. Thank you. I will try some different possibilities. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 21:34 ` Keith Wright 2010-12-01 22:19 ` Hans Aberg 2010-12-01 22:43 ` Hans Aberg @ 2010-12-03 15:06 ` Hans Aberg 2 siblings, 0 replies; 17+ messages in thread From: Hans Aberg @ 2010-12-03 15:06 UTC (permalink / raw) To: Keith Wright; +Cc: guile-user On 1 Dec 2010, at 22:34, Keith Wright wrote: >> One can set the constants to functions that evaluate >> to themselves. One use would be expressions like >> (1 + f)(x). The () just shows up in the context above. > > I didn't really follow that, but in seems that > you want to be able to apply a list of functions > to a single argument, and get a list of the > results of applying each function separately > to the same argument. > > guile> > (define (fmap fs x) > (if (null? fs) > '() > (cons (apply (car fs) (list x)) > (fmap (cdr fs) x) ))) > > guile> (fmap (list sin cos) 2) > (0.909297426825682 -0.416146836547142) If I extend your function to one of pairs and non-pairs as well, then () becomes naturally a constant: (define (fmap fs x) (if (null? fs) '() (if (not (pair? fs)) (apply fs (list x)) (cons (fmap (car fs) x) (fmap (cdr fs) x))))) Then (fmap sqrt 2) --> 1.4142135623731 (fmap (list sin cos) 2) --> (0.909297426825682 -0.416146836547142) (fmap (cons sin cos) 2) --> (0.909297426825682 . -0.416146836547142) But also (fmap (list) 2) --> () So this acts essentially as an extension of the evaluator, if all expressions (f x1 ...) are replaced by (fmap f x1 ...). ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 16:28 List functions Hans Aberg 2010-12-01 17:35 ` Joel James Adamson @ 2010-12-01 19:51 ` Andy Wingo 2010-12-01 19:56 ` Hans Aberg 2010-12-02 9:57 ` Marco Maggi 2 siblings, 1 reply; 17+ messages in thread From: Andy Wingo @ 2010-12-01 19:51 UTC (permalink / raw) To: Hans Aberg; +Cc: guile-user Hi Hans, On Wed 01 Dec 2010 17:28, Hans Aberg <haberg-1@telia.com> writes: > () x into (() x) What is the meaning of this? Did you mean () x into (map (lambda (f) (f x)) '()) ? Regards, Andy -- http://wingolog.org/ ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 19:51 ` Andy Wingo @ 2010-12-01 19:56 ` Hans Aberg 0 siblings, 0 replies; 17+ messages in thread From: Hans Aberg @ 2010-12-01 19:56 UTC (permalink / raw) To: Andy Wingo; +Cc: guile-user On 1 Dec 2010, at 20:51, Andy Wingo wrote: >> () x into (() x) > > What is the meaning of this? > > Did you mean > > () x into (map (lambda (f) (f x)) '()) > > ? I am trying to eliminate the "\" of the Haskell binding syntax \ ... - > f, by making the parser grammar rule for ... the same as evaluation rule f ... Then, as one can define \() x -> f for thunks, also () x becomes available for evaluation. So the question is to bother giving it meaning. One possibility might be as a constant evaluation to itself () x = () for any argument. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-01 16:28 List functions Hans Aberg 2010-12-01 17:35 ` Joel James Adamson 2010-12-01 19:51 ` Andy Wingo @ 2010-12-02 9:57 ` Marco Maggi 2010-12-02 10:10 ` Marco Maggi ` (2 more replies) 2 siblings, 3 replies; 17+ messages in thread From: Marco Maggi @ 2010-12-02 9:57 UTC (permalink / raw) To: Hans Aberg; +Cc: guile-user "Hans Aberg" wrote: > I am writing on a parser that translates normal function > syntax in to Guile code. I do not know which scenario you are working with, but it is perfectly possible to convert the input syntax: ((sin , cos , tan) 1.2) to the output: ((lambda args (map (lambda (f) (apply f args)) (list sin cos tan))) 1.2) if you accept to write the input syntax expressions only as part of a macro use, let's call this macro H; so the macro use: (h ((sin , cos) 1.2)) can be expanded to: ((lambda args (map (lambda (f) (apply f args)) (list sin cos tan))) 1.2) It is also possible to write the H macro such that any expression with nested expressions can appear in its use; H can be made just like the built in syntax BEGIN but with syntax different from standard Scheme. Example: (h (display (+ 4 ((sin , cos) 1.2)))) Once you have H you can write a DEFINE/H syntax which works just like the standard DEFINE but accepts in its body the modified syntax: (define/h (doit x y) (display (+ x ((sin , cos) y)))) The tool to do it is the syntax-case macro system. HTH -- Marco Maggi ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-02 9:57 ` Marco Maggi @ 2010-12-02 10:10 ` Marco Maggi 2010-12-02 11:31 ` Hans Aberg 2010-12-02 16:06 ` Hans Aberg 2 siblings, 0 replies; 17+ messages in thread From: Marco Maggi @ 2010-12-02 10:10 UTC (permalink / raw) To: Hans Aberg; +Cc: guile-user "Marco Maggi" wrote: >"Hans Aberg" wrote: >> I am writing on a parser that translates normal function >> syntax in to Guile code. > > I do not know which scenario you are working with, but it > is perfectly possible to convert the input syntax: > > ((sin , cos , tan) 1.2) Sorry, I have been too quick: you cannot use "," because it has special meaning for the reader; but you can use another character like ":". -- Marco Maggi ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-02 9:57 ` Marco Maggi 2010-12-02 10:10 ` Marco Maggi @ 2010-12-02 11:31 ` Hans Aberg 2010-12-02 16:06 ` Hans Aberg 2 siblings, 0 replies; 17+ messages in thread From: Hans Aberg @ 2010-12-02 11:31 UTC (permalink / raw) To: Marco Maggi; +Cc: guile-user On 2 Dec 2010, at 10:57, Marco Maggi wrote: >> I am writing on a parser that translates normal function >> syntax in to Guile code. > > I do not know which scenario you are working with, ... I have a Bison/Flex parser/lexer combination that writes Guile code directly by calling Guile C-functions, some via C++ wrap I wrote. The expressions are not evaluated until after the construction, just as when one enter expressions in the Guile interpreter, which gives greater flexibility. So I am not limited by any syntax, only the Guile semantics, which is more general than that of Scheme, in view of that one by calling C- functions, one can build things that not possible in Scheme proper. By writing out the expression before evaluation, I get a Guile code expression. I think I may be able to solve the original problem. I am now thinking by making functions that are called as (f (x y) z), where some arguments are lists, which correspond to Haskell f (1, 2) 3 where f (x, y) z = x + y + z --> 6 > ...but it is > perfectly possible to convert the input syntax: > > ((sin , cos , tan) 1.2) > > to the output: > > ((lambda args > (map (lambda (f) > (apply f args)) > (list sin cos tan))) > 1.2) > > if you accept to write the input syntax expressions only as > part of a macro use, let's call this macro H; so the macro > use: > > (h > ((sin , cos) 1.2)) > > can be expanded to: > > ((lambda args > (map (lambda (f) > (apply f args)) > (list sin cos tan))) > 1.2) > > It is also possible to write the H macro such that any > expression with nested expressions can appear in its use; H > can be made just like the built in syntax BEGIN but with > syntax different from standard Scheme. Example: > > (h > (display (+ 4 ((sin , cos) 1.2)))) > > Once you have H you can write a DEFINE/H syntax which > works just like the standard DEFINE but accepts in its body > the modified syntax: > > (define/h (doit x y) > (display (+ x ((sin , cos) y)))) > > The tool to do it is the syntax-case macro system. > > HTH > -- > Marco Maggi ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-02 9:57 ` Marco Maggi 2010-12-02 10:10 ` Marco Maggi 2010-12-02 11:31 ` Hans Aberg @ 2010-12-02 16:06 ` Hans Aberg 2010-12-03 9:20 ` Hans Åberg 2 siblings, 1 reply; 17+ messages in thread From: Hans Aberg @ 2010-12-02 16:06 UTC (permalink / raw) To: guile-user Another problem: passing a list of length two to a function that takes two non-arguments. For example, (define h (lambda (x y) (display x) (display y))) and passing (list 1 2) to it. It is in the same context as before: I want to build functions like in Haskell f((1, 2), 3) where f = \((x, y), z) -> (x, y, z) --> (1,2,3) ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: List functions 2010-12-02 16:06 ` Hans Aberg @ 2010-12-03 9:20 ` Hans Åberg 0 siblings, 0 replies; 17+ messages in thread From: Hans Åberg @ 2010-12-03 9:20 UTC (permalink / raw) To: Hans Aberg; +Cc: guile-user On 2 Dec 2010, at 17:06, Hans Aberg wrote: > Another problem: passing a list of length two to a function that > takes two non-arguments. For example, > (define h (lambda (x y) (display x) (display y))) > and passing (list 1 2) to it. > > It is in the same context as before: I want to build functions like > in Haskell > f((1, 2), 3) where f = \((x, y), z) -> (x, y, z) > --> (1,2,3) I found that this is possible by: (define f (lambda (a z) (primitive-eval (cons (lambda (x y) (+ x y z)) a)))) Then (f (list 1 2) 3) --> 6 The primitive "list" is important here, as shown in the examples by Keith. So it seems one should type data-lists by adding this symbol. But it is not available in the C-interface as symbol, so I added it in my interface, and in fact a variation called "tuple", which is the same as "list", only that (tuple x) --> x. ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2010-12-03 15:06 UTC | newest] Thread overview: 17+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-12-01 16:28 List functions Hans Aberg 2010-12-01 17:35 ` Joel James Adamson 2010-12-01 17:48 ` Hans Aberg 2010-12-01 19:20 ` Keith Wright 2010-12-01 19:50 ` Hans Aberg 2010-12-01 20:26 ` Hans Aberg 2010-12-01 21:34 ` Keith Wright 2010-12-01 22:19 ` Hans Aberg 2010-12-01 22:43 ` Hans Aberg 2010-12-03 15:06 ` Hans Aberg 2010-12-01 19:51 ` Andy Wingo 2010-12-01 19:56 ` Hans Aberg 2010-12-02 9:57 ` Marco Maggi 2010-12-02 10:10 ` Marco Maggi 2010-12-02 11:31 ` Hans Aberg 2010-12-02 16:06 ` Hans Aberg 2010-12-03 9:20 ` Hans Åberg
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).