* values->list elements
@ 2006-06-13 1:19 Jon Wilson
2006-06-13 17:20 ` szgyg
2006-06-13 21:17 ` Neil Jerram
0 siblings, 2 replies; 12+ messages in thread
From: Jon Wilson @ 2006-06-13 1:19 UTC (permalink / raw)
Hi y'all,
Is there any sensible way to implement the following semantics:
(+ (values 1 2))
==>
3
Or perhaps with a macro of some sort (but preferably as above)...
(+ (values->list-elements (values 1 2)))
==>
3
The intermediate step (after the macro expansion I guess) would look like
(+ 1 2)
==>
3
It seems like this would make multiple values much much more useful.
Regards,
Jon
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: values->list elements
2006-06-13 1:19 values->list elements Jon Wilson
@ 2006-06-13 17:20 ` szgyg
2006-06-13 19:02 ` Jonathan Wilson
2006-06-13 21:14 ` Neil Jerram
2006-06-13 21:17 ` Neil Jerram
1 sibling, 2 replies; 12+ messages in thread
From: szgyg @ 2006-06-13 17:20 UTC (permalink / raw)
Jon Wilson wrote:
> Is there any sensible way to implement the following semantics:
>
> (+ (values 1 2))
> ==>
> 3
>
> Or perhaps with a macro of some sort (but preferably as above)...
>
> (+ (values->list-elements (values 1 2)))
> ==>
> 3
! untested code !
(define-macro (values->list vs)
`(call-with-values (lambda () ,vs) list))
(apply + (values->list (values 1 2 3)))
or
(define-macro (make-cockeyed-function f)
`(lambda (vs) (apply ,f (values->list vs))))
((make-cockeyed-function +) (values 1 2 3))
> The intermediate step (after the macro expansion I guess) would look like
>
> (+ 1 2)
No, this is impossible without redefining +. A macro produces 1 sexp,
not more.
> It seems like this would make multiple values much much more useful.
szgyg
ps: GNU Free Software Directory list guile-1.6.7 as recent
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: values->list elements
2006-06-13 17:20 ` szgyg
@ 2006-06-13 19:02 ` Jonathan Wilson
2006-06-16 5:51 ` szgyg
2006-06-13 21:14 ` Neil Jerram
1 sibling, 1 reply; 12+ messages in thread
From: Jonathan Wilson @ 2006-06-13 19:02 UTC (permalink / raw)
Hi szgyg,
szgyg wrote:
> No, this is impossible without redefining +. A macro produces 1 sexp,
> not more.
>
This is exactly what I am getting at. values does return more than 1
sexp, but the mechanisms for using that are clumsy and painful. It
seems that if values returns multiple s-expressions, then they should be
treated as multiple s-expressions. In between a set of parentheses, N
s-expressions are usually treated as N elements of a list. Why should
values be any different?
(list 0 (values 1 2) 3)
==>
(0 #<values(1 2)> 3)
This is strange. If we had
(list 0 (values 1 2) 3)
==>
(0 1 2 3)
Then multiple values would actually be useful.
Regards,
Jon
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: values->list elements
2006-06-13 19:02 ` Jonathan Wilson
@ 2006-06-16 5:51 ` szgyg
2006-06-16 8:00 ` Neil Jerram
0 siblings, 1 reply; 12+ messages in thread
From: szgyg @ 2006-06-16 5:51 UTC (permalink / raw)
Cc: guile-user
Jonathan Wilson wrote:
> szgyg wrote:
>> No, this is impossible without redefining +. A macro produces 1 sexp,
>> not more.
>
> This is exactly what I am getting at.
Oh, yes, I see.
This isn't a new idea, but the original semantic.
| (this is not a serious proposal for a language extension,
| but only an example):
| (1) Wherever n consecutive arguments might be written in
| a function call, one may instead write {f x1 ... xm}n,
| where n is a positive integer. The "function" f must
| return n values, which are used as n arguments
| in the function call.
| (2) The primitive (values x1 ... xn) returns its n arguments
| as its n values. Thus writing "{values x1 ... xn}n" is
| the same as writing "x1 ... xn" as arguments in a
| function call.
[Guy L. Steele: LAMBDA: The Ultimate Declarative, 1976, p 18-19]
I think however, that explicit function transformer is a reasonable alternative.
szgyg
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: values->list elements
2006-06-16 5:51 ` szgyg
@ 2006-06-16 8:00 ` Neil Jerram
2006-06-16 18:15 ` szgyg
0 siblings, 1 reply; 12+ messages in thread
From: Neil Jerram @ 2006-06-16 8:00 UTC (permalink / raw)
Cc: guile-user
szgyg <szgyg@freemail.hu> writes:
> This isn't a new idea, but the original semantic.
>
> | (this is not a serious proposal for a language extension,
> | but only an example):
> | (1) Wherever n consecutive arguments might be written in
> | a function call, one may instead write {f x1 ... xm}n,
> | where n is a positive integer. The "function" f must
> | return n values, which are used as n arguments
> | in the function call.
> | (2) The primitive (values x1 ... xn) returns its n arguments
> | as its n values. Thus writing "{values x1 ... xn}n" is
> | the same as writing "x1 ... xn" as arguments in a
> | function call.
>
> [Guy L. Steele: LAMBDA: The Ultimate Declarative, 1976, p 18-19]
Interesting! So how come RnRS turned out not to include this?
Regards,
Neil
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: values->list elements
2006-06-13 17:20 ` szgyg
2006-06-13 19:02 ` Jonathan Wilson
@ 2006-06-13 21:14 ` Neil Jerram
1 sibling, 0 replies; 12+ messages in thread
From: Neil Jerram @ 2006-06-13 21:14 UTC (permalink / raw)
Cc: guile-user
szgyg <szgyg@freemail.hu> writes:
> (define-macro (values->list vs)
> `(call-with-values (lambda () ,vs) list))
>
> (apply + (values->list (values 1 2 3)))
Yes, but why does this need to be a macro?
(define (values->list vs)
(call-with-values (lambda () vs) list))
> or
>
> (define-macro (make-cockeyed-function f)
> `(lambda (vs) (apply ,f (values->list vs))))
Same here, I think.
Regards,
Neil
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: values->list elements
2006-06-13 1:19 values->list elements Jon Wilson
2006-06-13 17:20 ` szgyg
@ 2006-06-13 21:17 ` Neil Jerram
2006-06-13 22:04 ` Jonathan Wilson
1 sibling, 1 reply; 12+ messages in thread
From: Neil Jerram @ 2006-06-13 21:17 UTC (permalink / raw)
Cc: guile-user
Jon Wilson <j85wilson@fastmail.fm> writes:
> The intermediate step (after the macro expansion I guess) would look like
>
> (+ 1 2)
> ==>
> 3
>
> It seems like this would make multiple values much much more useful.
I've often thought that too. IMO multiple values per R5RS are a
pretty half-baked concept.
Regards,
Neil
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2006-06-19 1:12 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-13 1:19 values->list elements Jon Wilson
2006-06-13 17:20 ` szgyg
2006-06-13 19:02 ` Jonathan Wilson
2006-06-16 5:51 ` szgyg
2006-06-16 8:00 ` Neil Jerram
2006-06-16 18:15 ` szgyg
2006-06-19 0:51 ` Jon Wilson
2006-06-19 1:12 ` Per Bothner
2006-06-13 21:14 ` Neil Jerram
2006-06-13 21:17 ` Neil Jerram
2006-06-13 22:04 ` Jonathan Wilson
2006-06-13 22:24 ` Per Bothner
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).