From ... Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news-x2.support.nl!deine.net!hamster.europeonline.net!newsfeed.europeonline.net!nslave.kpnqwest.net!nloc.kpnqwest.net!nmaster.kpnqwest.net!nreader2.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: Constructing array inside function [newbie] References: <87it87dv9b.fsf@toadmail.com> Mail-Copies-To: never From: Erik Naggum Message-ID: <3224591965937406@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 65 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 08 Mar 2002 15:59:16 GMT X-Complaints-To: newsmaster@KPNQwest.no X-Trace: nreader2.kpnqwest.net 1015603156 193.71.199.50 (Fri, 08 Mar 2002 16:59:16 MET) NNTP-Posting-Date: Fri, 08 Mar 2002 16:59:16 MET Xref: archiver1.google.com comp.lang.lisp:28129 * Jeremy Whetzel | [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 suggest you do this, instead: (defun create-array (new-array) (make-array 4 :initial-element 'blank)) and in your caller do (let ((name-of-array (create-array))) ...) or, if this is a global resource: (defparameter *name-of-array* (create-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.