[I'm extremely new to CL. Please excuse, but feel free to correct, any inaccuracies in my terminology. Thanks.]
Hi,
I'm trying to create a function that, given a name of a new array as an argument, creates a new array of a default length. This is so that I can use one function to easily setup the array initially, and then I want to create other functions that abstract the process of editing the various elements inside of the array. Here is the code I'm using:
When the 'print' fires from inside the function, everything looks fine. But i I try this:
(print name-of-array)
I get the following:
*** - EVAL: variable NAME-OF-ARRAY has no value
I'm using CLISP. I'm not sure what I'm doing wrong. What I want is for the newly created array to be accessable outside of the function. I tried using defparameter, but that didn't seem to work either. Any pointers are GREATLY appreciated.
The third solution is to modify the symbol-table entry for this given symbol. This is closest to the original, but generally not considered "nice". However, if this is what you need...
* Jeremy Whetzel <li...@toadmail.com> | [I'm extremely new to CL. Please excuse, but feel free to correct, any | inaccuracies in my terminology. Thanks.]
It seems that you are still writing in some other language.
| I'm trying to create a function that, given a name of a new array as an | argument, creates a new array of a default length.
This is not how we do things in Common Lisp.
| This is so that I can use one function to easily setup the array | initially, and then I want to create other functions that abstract the | process of editing the various elements inside of the array.
The function should simply return the object you have created, and your caller should bind it. The reason for this is that you cannot pass a reference to any sub-object storage location into which your called function can store the value. This is quite crucial to understand if you are going to write Common Lisp in Common Lisp.
| (defun create-array(new-array) | (setf new-array (make-array 4 :initial-element 'blank)) | (print new-array)) | | Then I call it using: | | (create-array 'name-of-array)
| I'm using CLISP. I'm not sure what I'm doing wrong.
Basically, you are still writing in some other language. You have to let go of your desire to think you know what you are doing and start over as a novice before you can actually know what you are doing.
| What I want is for the newly created array to be accessable outside of | the function. I tried using defparameter, but that didn't seem to work | either. Any pointers are GREATLY appreciated.
I hope the above is more helpful than receiving advice on how you should accomplish what you should not want to do. Good luck learning Common Lisp and unlearning bad habits from other languages. As you have seen here in another response, not all those who think they know Common Lisp have unlearned their old bad habits and may still think that helping people with their explicit problem is better than trying to find and solve their underlying problem.
/// -- In a fight against something, the fight has value, victory has none. In a fight for something, the fight is a loss, victory merely relief.
In article <3224591965937...@naggum.net>, Erik Naggum wrote: > I hope the above is more helpful than receiving advice on how you should > accomplish what you should not want to do. Good luck learning Common > Lisp and unlearning bad habits from other languages. As you have seen > here in another response, not all those who think they know Common Lisp > have unlearned their old bad habits and may still think that helping > people with their explicit problem is better than trying to find and > solve their underlying problem.
I guess you are referring to me. I was hoping the atrocious ugliness of ``with-f-and-a'' was so glaring that it was the best way to convince the OP in that thread that what he was trying to achieve was wrong in the first place. :-)
Regards, -- Nils Goesche "The sooner all the animals are dead, the sooner we'll find their money." -- Ed Bluestone PGP key ID 0x42B32FC9
* Nils Goesche <car...@cartan.de> | I guess you are referring to me.
Not at all. I was referring to a fellow Norwegian who is permanently clueless, yet very "helpful", so people get much further astray than they were to begin with. With luck, you thought it was you because you have been relieved of his "helpful" response. It is important to realize when somebody would be hurt by being helped to achieve what they ask for, and _not_ to hurt people who ask for help in hurting themselves. Some of the clueless "good samaritans" out there never seem to learn this. Since this particular cretin is one of those who go totally bananas when he is not allowed to wear his halo after helping to hurt someone, I find it vital to newsgroup peace not to name him, so at least he has a choice of not responding and thus keeping the mystery of his identity instead of making it obvious that he does not even understand when to shut up. So, in summary, no, it was not you I referred to.
/// -- In a fight against something, the fight has value, victory has none. In a fight for something, the fight is a loss, victory merely relief.
Erik Naggum <e...@naggum.net> writes: > It seems that you are still writing in some other language.
Now looking at it, yes, this seems to be the case.
> The function should simply return the object you have created, and your > caller should bind it. The reason for this is that you cannot pass a > reference to any sub-object storage location into which your called > function can store the value. This is quite crucial to understand if you > are going to write Common Lisp in Common Lisp.
I need to let this one maranade in my mind a bit. Being [fairly] new to programming in general, and newer still to CL, it's still a bit to wrap my head around, although the example helps quite a bit.
> I hope the above is more helpful than receiving advice on how you should > accomplish what you should not want to do. Good luck learning Common > Lisp and unlearning bad habits from other languages. As you have seen > here in another response, not all those who think they know Common Lisp > have unlearned their old bad habits and may still think that helping > people with their explicit problem is better than trying to find and > solve their underlying problem.
Sometimes it can be difficult to solve an underlying problem when one doesn't realize there's a problem to begin with. Thanks for the pointer. This is just the type of advice I need and was looking for.
> The third solution is to modify the symbol-table entry for this given > symbol. This is closest to the original, but generally not > considered "nice". However, if this is what you need...
In article <3224591965937...@naggum.net>, Erik Naggum <e...@naggum.net> wrote:
> You have to let > go of your desire to think you know what you are doing and start over as > a novice before you can actually know what you are doing.