Qbasicnews.com

Full Version: Another LISP Question (should be easy)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
What is the equivalent of INPUT a$ in LISP? I need the program to be able to interact through something other than the command editor...
Well, this is kinda another R.T.F.M. moment, but oh, I just did it:

Code:
(setq var (read T))

This sets the variable "var" with the return value of (read T) which means "read from Terminal".
Thanks.

I have "On Lisp" by Paul Graham and "Structure and Interpretation of Computer programs" and it wasn't there.

Damn F.M.
I just read the XLISP.MAN file which comes with the lisp interpreter Wink Every command is there.
it's not a manual it's a listing. OR at least what I have. (almost) No examples. I tried "input" and couldn't find a thing.

Anyways, I need to be able to use more than one charater, and I need to print them, in LISP:

Code:
input "type the coordinates"; x; y 'edit
print "your coordinates are" + x + y
The first one I need one whitespace between 'em.

The second one I need to use x and y as strings instead of numbers.. I have a +str function:

(defun +str (a b) (concatenate 'string a b))

If you could just help me on these two points, that'd be great. I'll post the prog when it's done!

:bounce:
Forgot to mention: the terminal code doesn't work because it crashes to a DOS window. And I can't get back to the Windows program without closing it.
Which version do you have? the (input T) is the standard way. It is used in Unix old machines, Linux terminals, Windows DOS boxes ... I don't know another way to do that.

And to ask the user to enter two values, you simply can't at least the user enters a list and you process it to change the values.

Code:
(setq what (input T))
(setq x (car what))
(setq y (cadr what))

Stop thinking about LISP like an imperative language, such as QB. LISP is intended to do different things with ease such as AI, not like QB. The approach is different. LISP is a FUNCTIONAL language, not intended to make user friendly interfaces or shiny wells and whistles.
I have to make an interface for my program. (dots and boxes)

I guess I'll just do VAL.

(edit) I actually need STR$ first, so:
(edit) Forgot to change val to str$..

Code:
(defun +str (a b) (concatenate 'string a b))

(defun str$(n) (let()
(if (<= n 9) (let()
(len2 n)
)(let() ;else
(+str (str2$ (mod n 10)) (str$ (/ (- n (mod n 10)) 10)))
)) ;end if
)) ;end str$

(defun str2$ (n) (let()
(case n
(0 "0")
(1 "1")
(2 "2")
(3 "3")
(4 "4")
(5 "5")
(6 "6")
(7 "7")
(8 "8")
(9 "9")
) ;end select
)) ;end str$2
VAL

:lol:

Code:
(defun right$ (x a) (subseq x (- (length x) a) (length x)))

(defun val(n) (let()
(if (= (length n) 1)
(val2 n)
(+ (* 10 (val (subseq n 0 (- (length n) 1)))) (val2 (right$ n 1)))
) ;end if
)) ;end val

(defun val2 (n) (let()
(if (equalp n "0") 0
(if (equalp n "1") 1
(if (equalp n "2") 2
(if (equalp n "3") 3
(if (equalp n "4") 4
(if (equalp n "5") 5
(if (equalp n "6") 6
(if (equalp n "7") 7
(if (equalp n "8") 8
(if (equalp n "9") 9
))))))))))
)) ;end val2
Pages: 1 2