Subject: Re: Constructing array inside function [newbie]
From: Erik Naggum <>
Date: Fri, 08 Mar 2002 15:59:16 GMT
Newsgroups: comp.lang.lisp
Message-ID: <>

* 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.