Subject: Re: LISP to Scheme
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1998/01/18
Newsgroups: comp.lang.scheme
Message-ID: <69s2bn$1g12s@fido.asd.sgi.com>

<krispos@erols.com> wrote:
+---------------
|  I have been using LISP for a couple of months and now am trying to
| switch to Scheme. I'm having a little difficulty getting Scheme to map
| user input to lists/vectors. Before in LISP I used code like this:
| 
| (defun final-make () 
| (format t "~&And Finally enter the  ship's name: ")
| (setf helper1 (read)) ...
...
| read clearly doesn't function the same way in Scheme.
+---------------

Well, you don't say what format user input you expect, but Scheme "read"
*does* work more or less the same as Lisp's, namely, it expects S-expressions:

	> (define helper1 #f)   ; must "define" before using "set!"
	> (define (final-make)
	    (display "And finally enter the ship's name: ")
	    (set! helper1 (read)))
	> (final-make)
	And finally enter the ship's name: (USS Sally Forth)
	> helper1
	(uss sally forth)

Note: In Scheme one would usually use a less imperative style, so that rather
than set a global variable one would simply return the value read:

	> (define (prompt-then-read prompt)
	    (display prompt)
	    (read))
	> (define ship-name
	    (prompt-then-read "And finally enter the ship's name: "))
	And finally enter the ship's name: (SS Trash Hauler)
	> ship-name
	(ss trash hauler)
	> 

+---------------
| or this...
| (mapcar #'stat-define stranger)))
| 
| (defun stat-define (x)
| (format t "~& Enter ~a value for newship:"
| x)
| (helper x)
| (setf stranger2 (append stranger2 help)))))
| 
| (defun helper (x)
| (setf help (list x (read)))))
+---------------

Again, too many side effects for my taste. I'd write it more like this:

	> (define (displays . ls)	; no "format" in R4RS
	    (for-each display ls))
	> (define (stat-define x)
	    (displays "Enter value for '" x "' attribute for new ship: ")
	    (list x (read)))
	> (define new-ship-attrs
	    (map stat-define '(length tonnage armaments)))
	Enter value for 'length' attribute for new ship: 7000
	Enter value for 'tonnage' attribute for new ship: 1400
	Enter value for 'armaments' attribute for new ship:
		(guns missiles wet-noodles)
	> new-ship-attrs
	((length 7000) (tonnage 1400) (armaments (guns missiles wet-noodles)))
	> 


-Rob

-----
Rob Warnock, 7L-551		rpw3@sgi.com   http://reality.sgi.com/rpw3/
Silicon Graphics, Inc.		Phone: 650-933-1673 [New area code!]
2011 N. Shoreline Blvd.		FAX: 650-933-4392
Mountain View, CA  94043	PP-ASEL-IA