Qbasicnews.com

Full Version: Need LISP Help!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
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..
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).
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. Sad
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.
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)
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 Wink
what is lisp? a programming language? what do you use it for?
I have that same question
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? Sad
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 Wink 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 Smile. Maybe loosecaboose could help too...
Pages: 1 2 3