unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* parallel with no exprs
@ 2003-06-08 22:07 Kevin Ryde
  2003-06-09  8:35 ` Mikael Djurfeldt
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Ryde @ 2003-06-08 22:07 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 551 bytes --]

I tried using parallel with no expressions,

	(use-modules (ice-9 threads))
	(call-with-values
	    (lambda ()
	      (parallel))
	  (lambda ()
	    (display "hi\n")))

but got

	ERROR: In procedure lambda:
	ERROR: bad body

Is parallel allowed to be called with no expressions?  It'd be pretty
silly to write that deliberately, but perhaps it could arise from a
simple-minded macro expansion or something.

        * threads.scm (parallel): For no forms, use `(values)' not `(begin)'.

        * tests/threads.test: New file, exercising "parallel".


[-- Attachment #2: threads.scm.parallel-empty.diff --]
[-- Type: text/plain, Size: 334 bytes --]

--- threads.scm.~1.21.~	2003-04-28 07:51:19.000000000 +1000
+++ threads.scm	2003-06-08 14:31:57.000000000 +1000
@@ -182,7 +182,7 @@
 	%thread-handler)))
 
 (define-macro (parallel . forms)
-  (cond ((null? forms) '(begin))
+  (cond ((null? forms) '(values))
 	((null? (cdr forms)) (car forms))
 	(else
 	 (let ((vars (map (lambda (f)

[-- Attachment #3: threads.test --]
[-- Type: text/plain, Size: 1452 bytes --]

;;;; threads.test --- Tests for Guile threading.    -*- scheme -*-
;;;;
;;;; Copyright 2003 Free Software Foundation, Inc.
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2, or (at your option)
;;;; any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this software; see the file COPYING.  If not, write to
;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
;;;; Boston, MA 02111-1307 USA

(use-modules (ice-9 threads)
	     (test-suite lib))


(with-test-prefix "parallel"
  (pass-if "0"
    (call-with-values
	(lambda ()
	  (parallel))
      (lambda ()
	#t)))
  
  (pass-if "1"
    (call-with-values
	(lambda ()
	  (parallel 1))
      (lambda (x)
	(equal? x 1))))
  
  (pass-if "1 2"
    (call-with-values
	(lambda ()
	  (parallel 1 2))
      (lambda (x y)
	(and (equal? x 1)
	     (equal? y 2)))))
  
  (pass-if "1 2 3"
    (call-with-values
	(lambda ()
	  (parallel 1 2 3))
      (lambda (x y z)
	(and (equal? x 1)
	     (equal? y 2)
	     (equal? z 3))))))

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: parallel with no exprs
  2003-06-08 22:07 parallel with no exprs Kevin Ryde
@ 2003-06-09  8:35 ` Mikael Djurfeldt
  2003-06-12  1:54   ` Kevin Ryde
  0 siblings, 1 reply; 7+ messages in thread
From: Mikael Djurfeldt @ 2003-06-09  8:35 UTC (permalink / raw)
  Cc: djurfeldt

Kevin Ryde <user42@zip.com.au> writes:

> I tried using parallel with no expressions,
>
> 	(use-modules (ice-9 threads))
> 	(call-with-values
> 	    (lambda ()
> 	      (parallel))
> 	  (lambda ()
> 	    (display "hi\n")))
>
> but got
>
> 	ERROR: In procedure lambda:
> 	ERROR: bad body
>
> Is parallel allowed to be called with no expressions?  It'd be pretty
> silly to write that deliberately, but perhaps it could arise from a
> simple-minded macro expansion or something.
>
>         * threads.scm (parallel): For no forms, use `(values)' not `(begin)'.
>
>         * tests/threads.test: New file, exercising "parallel".
>
>
> --- threads.scm.~1.21.~	2003-04-28 07:51:19.000000000 +1000
> +++ threads.scm	2003-06-08 14:31:57.000000000 +1000
> @@ -182,7 +182,7 @@
>  	%thread-handler)))
>  
>  (define-macro (parallel . forms)
> -  (cond ((null? forms) '(begin))
> +  (cond ((null? forms) '(values))
>  	((null? (cdr forms)) (car forms))
>  	(else
>  	 (let ((vars (map (lambda (f)

Please don't apply this patch.

The original code is correct.  The error instead lies in the use of
parallel.  You'll find that for example

 	(use-modules (ice-9 threads))
 	(call-with-values
 	    (lambda ()
              (display "hello\n")
 	      (parallel))
 	  (lambda ()
 	    (display "hi\n")))

will be accepted.  (lambda () (parallel)) correctly yields an error
message since that is a lambda with no expressions in the body.

Best regards,
Mikael


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: parallel with no exprs
  2003-06-09  8:35 ` Mikael Djurfeldt
@ 2003-06-12  1:54   ` Kevin Ryde
  2003-06-12  9:27     ` Mikael Djurfeldt
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Ryde @ 2003-06-12  1:54 UTC (permalink / raw)


Mikael Djurfeldt <mdj@kvast.blakulla.net> writes:
>
>  	(use-modules (ice-9 threads))
>  	(call-with-values
>  	    (lambda ()
>               (display "hello\n")
>  	      (parallel))
>  	  (lambda ()
>  	    (display "hi\n")))

I get

	hello
	ERROR: Wrong number of arguments to #<procedure #f ()>

I'd seen (parallel) expanding to (begin), which was what made me think
it was the (begin) that might not be right, since the following gives
the same error.

	(call-with-values
	    (lambda ()
	      (display "hi\n")
	      (begin))
	  (lambda ()
	    (display "bye\n")))

> (lambda () (parallel)) correctly yields an error
> message since that is a lambda with no expressions in the body.

Ah, somehow I missed that (lambda () (begin)) is itself an empty body.
Bit subtle that, since of course it doesn't look empty :-).


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: parallel with no exprs
  2003-06-12  1:54   ` Kevin Ryde
@ 2003-06-12  9:27     ` Mikael Djurfeldt
  2003-06-13 23:48       ` Kevin Ryde
  0 siblings, 1 reply; 7+ messages in thread
From: Mikael Djurfeldt @ 2003-06-12  9:27 UTC (permalink / raw)
  Cc: djurfeldt

Kevin Ryde <user42@zip.com.au> writes:

> Mikael Djurfeldt <mdj@kvast.blakulla.net> writes:
>>
>>  	(use-modules (ice-9 threads))
>>  	(call-with-values
>>  	    (lambda ()
>>               (display "hello\n")
>>  	      (parallel))
>>  	  (lambda ()
>>  	    (display "hi\n")))
>
> I get
>
> 	hello
> 	ERROR: Wrong number of arguments to #<procedure #f ()>

Oops.  The second lambda should have (x) as formal parameters.
But this error is independent from the problem we are discussing.
(parallel) correctly expands to (begin).  In our implementation,
(begin) evaluates to #<unspecified> which is 1 value, so the second
lambda must take 1 argument.

> I'd seen (parallel) expanding to (begin), which was what made me think
> it was the (begin) that might not be right, since the following gives
> the same error.
>
> 	(call-with-values
> 	    (lambda ()
> 	      (display "hi\n")
> 	      (begin))
> 	  (lambda ()
> 	    (display "bye\n")))
>
>> (lambda () (parallel)) correctly yields an error
>> message since that is a lambda with no expressions in the body.
>
> Ah, somehow I missed that (lambda () (begin)) is itself an empty body.
> Bit subtle that, since of course it doesn't look empty :-).

:-)


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: parallel with no exprs
  2003-06-12  9:27     ` Mikael Djurfeldt
@ 2003-06-13 23:48       ` Kevin Ryde
  2003-06-16 18:45         ` Mikael Djurfeldt
  0 siblings, 1 reply; 7+ messages in thread
From: Kevin Ryde @ 2003-06-13 23:48 UTC (permalink / raw)


Mikael Djurfeldt <djurfeldt@nada.kth.se> writes:
>
> Oops.  The second lambda should have (x) as formal parameters.
> But this error is independent from the problem we are discussing.
> (parallel) correctly expands to (begin).

Are you sure you want it that way?  I guess it'd be necessary to
document that parallel of N forms returns N values except that 0 forms
returns 1 unspecified value.

Maybe 0 forms shouldn't be documented at all, could quietly ignore it
as too degenerate.

(I'm not especially worried one way or the other, I only arrived at it
from looking to add to the manual.)

> In our implementation,
> (begin) evaluates to #<unspecified> which is 1 value, so the second
> lambda must take 1 argument.

Yes I thought it might be the unspecified literalism, or rather the
literalism of unspecified :-).


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: parallel with no exprs
  2003-06-13 23:48       ` Kevin Ryde
@ 2003-06-16 18:45         ` Mikael Djurfeldt
  2003-06-19  1:40           ` Kevin Ryde
  0 siblings, 1 reply; 7+ messages in thread
From: Mikael Djurfeldt @ 2003-06-16 18:45 UTC (permalink / raw)
  Cc: djurfeldt

Kevin Ryde <user42@zip.com.au> writes:

> Mikael Djurfeldt <djurfeldt@nada.kth.se> writes:
>>
>> Oops.  The second lambda should have (x) as formal parameters.
>> But this error is independent from the problem we are discussing.
>> (parallel) correctly expands to (begin).
>
> Are you sure you want it that way?  I guess it'd be necessary to
> document that parallel of N forms returns N values except that 0 forms
> returns 1 unspecified value.

No.  In fact, I'm not sure at all.  In fact,

I am no longer the Guile developer who says "(parallel) should expand
to (begin)".  I am now the Guile developer who says "(parallel) should
expand to (values)"!

Please do apply your patch.

(Sorry for not paying attention.)

> (I'm not especially worried one way or the other, I only arrived at it
> from looking to add to the manual.)

Good thing to express things with words...

>> In our implementation,
>> (begin) evaluates to #<unspecified> which is 1 value, so the second
>> lambda must take 1 argument.
>
> Yes I thought it might be the unspecified literalism, or rather the
> literalism of unspecified :-).

The question is if (begin) --> #<unspecified> is correct.  Probably
so, because (begin) is a sequence and it should probably always return
1 value...

M


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: parallel with no exprs
  2003-06-16 18:45         ` Mikael Djurfeldt
@ 2003-06-19  1:40           ` Kevin Ryde
  0 siblings, 0 replies; 7+ messages in thread
From: Kevin Ryde @ 2003-06-19  1:40 UTC (permalink / raw)


Mikael Djurfeldt <djurfeldt@nada.kth.se> writes:
>
> Please do apply your patch.

Done.  I added my little test file too.

> Good thing to express things with words...

Though of course that's not to privilege literature over other arts.
:-)


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-06-19  1:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-06-08 22:07 parallel with no exprs Kevin Ryde
2003-06-09  8:35 ` Mikael Djurfeldt
2003-06-12  1:54   ` Kevin Ryde
2003-06-12  9:27     ` Mikael Djurfeldt
2003-06-13 23:48       ` Kevin Ryde
2003-06-16 18:45         ` Mikael Djurfeldt
2003-06-19  1:40           ` Kevin Ryde

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).