unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* Re: shift and reset, plus "while"
@ 2011-04-04 13:05 Wolfgang J Moeller
  2011-04-13  9:47 ` Andy Wingo
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Wolfgang J Moeller @ 2011-04-04 13:05 UTC (permalink / raw)
  To: Andy Wingo; +Cc: bug-guile

[-- Attachment #1: Type: TEXT/PLAIN, Size: 4643 bytes --]

Hi,

co-routine linkage problem solved!

All it takes, is taking care that each [full] continuation
seen by one co-routine are equivalent, so it doesn't matter
which one gets saved and restored. No continuation-barrier
or dynamic-wind required!

While not obvious at first glance, doing so is easy enough -
at least by "imperative" programming throughout. I believe that
now my co-routine linkage works for prompt-based reset/shift
just the same as for call/cc-based reset/shift.

===

My pet peeve: (while).

First a compiler bug (in V2.0.0),
plus mis-behaviour after a stack overflow:

| moeller@linux3-$ guile2 --no-auto-compile
| using readline (~/.guile) ...
| GNU Guile 2.0.0
| Copyright (C) 1995-2011 Free Software Foundation, Inc.
|
| Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
| This program is free software, and you are welcome to redistribute it
| under certain conditions; type `,show c' for details.
|
| Enter `,help' for help.
| scheme@(guile-user)> (display (while #f 1))
| <unnamed port>:0:0: In procedure #<procedure 887aa60 at <current input>:1:0 ()>:
| <unnamed port>:0:0: Throw to key `vm-error' with args `(vm-run "VM: Stack overflow" ())'.
|
| Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
| scheme@(guile-user) [1]>
| scheme@(guile-user) [1]> (display (while #f 1))
| Segmentation fault
| moeller@linux3-$

You can
	(define (f) (display (while #f 1)))
which also gets the code wrong, and ,disassemble ...

Btw,
	(define (f) (while #f 1))
	(display (f))
does work (--> #<unspecified>), as does
	(while #f 1)
at top level.

===

Second, this is how I'd like to "improve" (while)
as currently provided by ice-9/boot.scm :

(a) to always have a well-defined result
(b) to allow for (break arg ...)
(c) to only take a single (call-with-prompt)
(d) to correct a buglet that currently transforms the non-operator `continue'
    into a function of arbitrarily many (as opposed to zero) arguments.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; {while} with `continue' and `break'.
;;
;;; wjm: Will the inliner eventually remove the prompt at compile-time
;;;      if it finds that neither `continue' nor `break' are used?
;;; NB. The optimization, as announced in ice-9/boot.scm, doesn't work out yet.
;;
;; returns:
;;	#f		on normal termination	- sort-of compatible to GUILE
;;						  which returns #<unspecified>
;;	#t		on (break)		- compatible
;;	(values v ...)	on (break v ...)	- compatible extension
;;
(define-syntax while
  (lambda (x)
    (syntax-case x ()
      ((while cond . body)
       #`(let ((tag (make-prompt-tag "while")))
	   (let lp ()
	     (call-with-prompt
	      tag
	      ;;
	      (lambda ()
		;;
		(define-syntax #,(datum->syntax #'while 'break)
		  (lambda (x)
		    (syntax-case x ()
		      ((_ . vals)
		       #'(abort-to-prompt tag #f . vals))
		      (_
		       #'(lambda vals
			   (apply abort-to-prompt tag #f vals))))))
		;;
		(define-syntax #,(datum->syntax #'while 'continue)
		  (lambda (x)
		    (syntax-case x ()
		      ((_)
		       #'(abort-to-prompt tag #t))
		      ((_ . args)
		       (syntax-violation 'continue "too many arguments" x))
		      (_
		       #'(lambda ()
			   (abort-to-prompt tag #t))))))
		;;
		(do ()
		    ((not cond) #f)
		  . body))
	      ;;
	      (lambda (k cont? . vals)
		(if cont?
		    (lp)
		    (or (null? vals)
			(apply values vals)))))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

NB. "body ..." (etc.) replaced by ". body" so my LISP-based Scheme can read it too.

As of V2.0.0, the modified macro runs into the same problems
as the built-in (while) shown above.

Feel free to select the modifications you like!

===

Just a hint: (GPLed) CLISP's compiler is written in LISP
and in my experience perfectly succeeds at removing all
redundant branches. Maybe something to look at?


Schöne Grüße,

Dr. Wolfgang J. Möller                   <moeller@gwdg.de>
Arbeitsgruppe IT-Infrastruktur         Tel. +49 551 201-1516
----------------------------------------------------- G W D G ----
Gesellschaft für wissenschaftliche Datenverarbeitung mbH Göttingen
Am Fassberg 11, 37077 Göttingen
E-Mail: gwdg@gwdg.de                   Tel.:   +49 (0)551 201-1510
URL:    http://www.gwdg.de             Fax:    +49 (0)551 201-2150
Geschäftsführer:            Prof. Dr. Oswald Haan, Dr. Paul Suren
Aufsichtsratsvorsitzender:  Prof. Dr. Christian Griesinger
Sitz der Gesellschaft:      Göttingen
Registergericht:            Göttingen  Handelsregister-Nr. B 598
------------------------------------------------------------------

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

end of thread, other threads:[~2011-06-17 16:09 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-04 13:05 shift and reset, plus "while" Wolfgang J Moeller
2011-04-13  9:47 ` Andy Wingo
2011-04-13 14:56   ` [shift and reset, plus] "while" Wolfgang J Moeller
2011-04-13 15:41     ` Andy Wingo
2011-04-13 17:31       ` Wolfgang J Moeller
2011-04-28 12:15         ` Andy Wingo
2011-04-29 12:12           ` {debug,read,readline,print}-{set!,disable,enable} Wolfgang J Moeller
2011-05-20  9:57             ` {debug,read,readline,print}-{set!,disable,enable} Andy Wingo
2011-05-22 11:53               ` {debug,read,readline,print}-{set!,disable,enable}, etc Wolfgang J Moeller
2011-06-17 16:09                 ` Andy Wingo
2011-04-13 15:17 ` shift and reset, plus "while" Mark H Weaver
2011-04-28 11:10 ` Andy Wingo
2011-04-28 14:44   ` Wolfgang J Moeller

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