Need LISP Help! - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: General (http://qbasicnews.com/newforum/forum-6.html) +--- Forum: General/Misc (http://qbasicnews.com/newforum/forum-18.html) +---- Forum: General Programming (http://qbasicnews.com/newforum/forum-20.html) +---- Thread: Need LISP Help! (/thread-119.html) |
Need LISP Help! - Agamemnus - 01-30-2003 My TAs and professors will prolly respond after everyone else... :o :bounce: :king: :rotfl: :king: :bounce: :o Problem with defun: (setq x (make-array '(5) :initial-element 0)) Creates an array x of size 5. (defun dim1 (x a) (setq x (make-array '(5) :initial-element 0))) (setq anynumber 0) (dim1 teststring anynumber) Also creates an array x of size 5. (defun dim1 (x a) (setq x (make-array '(a) :initial-element 0))) (dim1 teststring 7) Doesn't work. Says teststring is unbound. Aaaargh!!! Any ideas? Removing quote doesn't do anything.. Need LISP Help! - na_th_an - 01-31-2003 You need to define the function as follows Code: (defun dim1(x a) (setq x (make-array a :initial-element 0))) To use it, you have to use ' with the array variable you want to create. ' makes the expression not to be evaluated. You are getting the unbound error 'cause lisp tries to evaluate a symbol which hasn't been created. The correct call is: Code: (dim1 'string 7) Will create an array of 7 elements. (I've tested this in XLisp). ok thanks - Agamemnus - 01-31-2003 THANKS A LOT MAN!!! You're great! I still didn't get the reply from my TEACHERS; maybe I should give you my tuition $ instead? :roll: Oh one more thing: Instead of doing: (defun dim1 (x a) (make-array a :initial-element 0)) (setq string1 ('string1 5) How can I just make it do (dim1 string1 5)?? It doesn't seem to recognize setq as a permament operation inside scopes. Need LISP Help! - na_th_an - 01-31-2003 I don't quite understand your question. I'll make a guess. To dim an array directly, just... Code: XLISP> (setq x (make-array 5)) You don't need to have a program or define a function: you can enter the above line directly, and it will create the X variable with 5 empty (NIL) indexes. Need LISP Help! - Agamemnus - 01-31-2003 I want to be able to dim an array by just using (dim1 (name) (length)) (and dim2 -- 2 dimensions, and dim3 -- 3 dimensions) current code forces me to do: Code: (setq string1 (dim1 'string1 5)) (and I also wanted to have them default at 0) Need LISP Help! - na_th_an - 01-31-2003 Use defvar instead of setq. This makes a global variable: Code: LISP>(defun dim1(x a) (defvar x (make-array a :initial-element 0))) Now you can use this: Code: (dim1 'x 4) Now type X and see what happens Need LISP Help! - red_Marvin - 01-31-2003 what is lisp? a programming language? what do you use it for? Need LISP Help! - Neo - 01-31-2003 I have that same question Need LISP Help! - Agamemnus - 01-31-2003 Quote: what is lisp? a programming language? what do you use it for? :rotfl: :rotfl: :rotfl: :rotfl: Um... confusing other programmers!! :???: :???: :???: (LISP is difficult to learn.. I don't like it much) Thanks again na_th_an. But that only works for x.. how do I make it work for something else? Need LISP Help! - na_th_an - 01-31-2003 Lisp is the short of "List Processing". It is a functional language, so it is different from QB or C which are imperative languages. In Lisp everything is a list, even program code. You can use the program code like data, for example. It is very beautiful as a language. Its main application is with AI and some automatic reasoning. Agamemnus: I've been reading my documentation and testing and ... I DON'T KNOW Maybe it is some funny "funcall" action, but I can't quite remember how it was used. Please ask your teachers and post here the sollution. I'd like to know how, too . Maybe loosecaboose could help too... |