From: Emre Sevinc
Subject: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <87ek9tw8um.fsf@ileriseviye.org>
Maybe some of the Lisp meisters are going to help me:

I have two files:

grammar2dot.lisp:
======================================================
(in-package :cl-user)

(defpackage :org.ileriseviye.linear2tree
  (:use :common-lisp)
  (:export :produce-tree-output))

... some parameters, functions, etc

(defun produce-tree-output ()
  ... function body ...)
======================================================


grammar-web.lisp
======================================================
(defpackage :org.ileriseviye.grammar-web
  (:use 
   :common-lisp
   :net.aserve
   :net.html.generator
   :org.ileriseviye.linear2tree))

(in-package :org.ileriseviye.grammar-web)

;; let's see if we can run the function
(produce-tree-output)

... some functions related to web, etc. ...
=====================================================


As you see my purpose is to define two packages and
use a function called "produce-tree-output" in grammar-web.lisp 
(defining the package :org.ileriseviye.grammar-web) which is 
defined in grammar-web.lisp (defining the package 
:org.ileriseviye.grammar-web).

However when I hit C-c k in my Emacs+SLIME environment
when I'm editing the file grammar-web.lisp it says:

The function PRODUCE-TREE-OUTPUT is undefined.
   [Condition of type UNDEFINED-FUNCTION]

Bear in mind that the both files are in same directories.

I also receive the same error when I try to run a function
(defined in grammar-web.lisp) which also uses the produce-tree-output:

"got error The function ORG.ILERISEVIYE.LINEAR2TREE:PRODUCE-TREE-OUTPUT 
is undefined."

How can I reach one function defined in another file?

What am I doing wrong? Something wrong with parameters
passed to (in-package ...)?

Thanks in advance.

Happy hacking,

-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr

From: Edi Weitz
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <uzmshw8l0.fsf@agharta.de>
On Wed, 20 Jul 2005 22:55:29 +0300, Emre Sevinc <·····@bilgi.edu.tr> wrote:

> grammar2dot.lisp:
> ======================================================
> (in-package :cl-user)
>
> (defpackage :org.ileriseviye.linear2tree
>   (:use :common-lisp)
>   (:export :produce-tree-output))
>
> ... some parameters, functions, etc
>
> (defun produce-tree-output ()
>   ... function body ...)
> ======================================================

There's no IN-PACKAGE form which, after defining the
:ORG.ILERISEVIYE.LINEAR2TREE package, makes sure your function is
defined in that package (which I assume is what you want).  So, either
use

  (in-package :org.ileriseviye.linear2tree)

/before/ the DEFUN or write

  (defun org.ileriseviye.linear2tree:produce-tree-output ()
    ... function body ...)

Otherwise your function will live in CL-USER.

HTH,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Emre Sevinc
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <87u0ipz0e2.fsf@ileriseviye.org>
Edi Weitz <········@agharta.de> writes:

> On Wed, 20 Jul 2005 22:55:29 +0300, Emre Sevinc <·····@bilgi.edu.tr> wrote:
>
>> grammar2dot.lisp:
>> ======================================================
>> (in-package :cl-user)
>>
>> (defpackage :org.ileriseviye.linear2tree
>>   (:use :common-lisp)
>>   (:export :produce-tree-output))
>>
>> ... some parameters, functions, etc
>>
>> (defun produce-tree-output ()
>>   ... function body ...)
>> ======================================================
>
> There's no IN-PACKAGE form which, after defining the
> :ORG.ILERISEVIYE.LINEAR2TREE package, makes sure your function is
> defined in that package (which I assume is what you want).

Yes I want that produce-tree-output function be defined in
org.ileriseviye.linear2tree package and used from another file.


>  So, either
> use
>
>   (in-package :org.ileriseviye.linear2tree)
>
> /before/ the DEFUN or write
>
>   (defun org.ileriseviye.linear2tree:produce-tree-output ()
>     ... function body ...)
>
> Otherwise your function will live in CL-USER.

I have tried both options, however when I try to compile
only the grammar2dot.lisp I get:

-+  Style Warnings (3)
 |-- --> PROGN EVAL-WHEN SB-IMPL::%DEFUN SB-IMPL::%DEFUN SB-INT:NAMED-LAMBDA 
 |   ==>
 |     #'(SB-INT:NAMED-LAMBDA ORG.ILERISEVIYE.LINEAR2TREE::READ-BRACKETED-LIST
 |                            (STREAM CHAR)
 |                            (BLOCK
 |                                ORG.ILERISEVIYE.LINEAR2TREE::READ-BRACKETED-LIST
 |                              (READ-DELIMITED-LIST #\] STREAM)))
 |   The variable CHAR is defined but never used.
 |-- undefined function: RUN-PROGRAM
 `-- This function is undefined:
       RUN-PROGRAM


I tried it both as

grammar2dot.lisp
====================================================
(defpackage :org.ileriseviye.linear2tree
  (:use :common-lisp)
  (:export :produce-tree-output))

(in-package :org.ileriseviye.linear2tree)

... function and variable definitions as usual...
===================================================


and as

grammar2dot.lisp
====================================================
(in-package :cl-user)

(defpackage :org.ileriseviye.linear2tree
  (:use :common-lisp)
  (:export :produce-tree-output))

(in-package :org.ileriseviye.linear2tree)

... function and variable definitions as usual...
===================================================


I keep on getting the same error when I try to compile
the whole file using C-c k

What is the source of this problem? How can I correct it?
Why can't it find the Common Lisp function "run-program"?






-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr
From: Kent M Pitman
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <u3bq9i509.fsf@nhplace.com>
Emre Sevinc <·····@bilgi.edu.tr> writes:

> I have tried both options, however [...]

That you run into problems doesn't mean it was the wrong advice.

> when I try to compile
> only the grammar2dot.lisp I get:

>  |   The variable CHAR is defined but never used.
>  |-- undefined function: RUN-PROGRAM
>  `-- This function is undefined:
>        RUN-PROGRAM

shifting the namespace means things in cl-user are not in your new package.

you used COMMON-LISP (which you should have) not cl-user.
but you're neglecting that CL-USER may contain in it more than COMMON-LISP.
RUN-PROGRAM is not a function in COMMON-LISP, it's some implementation-defined
extension that is defined probably in some systemy package and imported
into CL-USER.  you need to find its proper package, where probably
(symbol-package 'cl-user::run-program) will tell you, and either import
that package (which will get you other random junk you probably don't know
about and may not want) or else call the package you get yourself. eg.,
if it's the system package, then SYSTEM:RUN-PROGRAM ... 
From: Emre Sevinc
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <87ll41yyz8.fsf@ileriseviye.org>
Kent M Pitman <······@nhplace.com> writes:

> Emre Sevinc <·····@bilgi.edu.tr> writes:
>
>> I have tried both options, however [...]
>
> That you run into problems doesn't mean it was the wrong advice.
>
>> when I try to compile
>> only the grammar2dot.lisp I get:
>
>>  |   The variable CHAR is defined but never used.
>>  |-- undefined function: RUN-PROGRAM
>>  `-- This function is undefined:
>>        RUN-PROGRAM
>
> shifting the namespace means things in cl-user are not in your new package.
>
> you used COMMON-LISP (which you should have) not cl-user.
> but you're neglecting that CL-USER may contain in it more than COMMON-LISP.
> RUN-PROGRAM is not a function in COMMON-LISP, it's some implementation-defined
> extension that is defined probably in some systemy package and imported
> into CL-USER.  you need to find its proper package, where probably
> (symbol-package 'cl-user::run-program) will tell you, and either import
> that package (which will get you other random junk you probably don't know
> about and may not want) or else call the package you get yourself. eg.,
> if it's the system package, then SYSTEM:RUN-PROGRAM ... 

It was SB-EXT (I just guessed it but knowing how to search it programmaticaly
using symbol-package is better).

":use"ing in defpackage SB-EXT solved my problem as Edi Weitz suggested.

However after reading your message I decided I do not want anything
but the run-program from SB-EXT so I removed that :use SB-EXT and
I used it as sb-ext:run-program in my package. It also worked as before,
no problems. I think that is better (am I right?)

This also made me think why run-program (or running external programs in
general) is not a part of the language definition.


-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr
From: Edi Weitz
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <uek9tw5he.fsf@agharta.de>
On Thu, 21 Jul 2005 00:00:27 +0300, Emre Sevinc <·····@bilgi.edu.tr> wrote:

> This also made me think why run-program (or running external
> programs in general) is not a part of the language definition.

If you look closely at your definition of RUN-PROGRAM you'll note that
it more or less specifies how to start a process on a Unix-like OS.
The CL standard, however, is not (only) about Lisp implementations on
Unix-like systems.  Other platforms (think Lisp Machine) might not
even have the notion of an external program that you can somehow
invoke.

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Kent M Pitman
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <uy881gnmi.fsf@nhplace.com>
Edi Weitz <········@agharta.de> writes:

> On Thu, 21 Jul 2005 00:00:27 +0300, Emre Sevinc <·····@bilgi.edu.tr> wrote:
> 
> > This also made me think why run-program (or running external
> > programs in general) is not a part of the language definition.
> 
> If you look closely at your definition of RUN-PROGRAM you'll note that
> it more or less specifies how to start a process on a Unix-like OS.
> The CL standard, however, is not (only) about Lisp implementations on
> Unix-like systems.  Other platforms (think Lisp Machine) might not
> even have the notion of an external program that you can somehow
> invoke.

Heh, indeed.  And, related to this, people used to ask why there was
no QUIT function in Lisp and the answer was always: are you sure you
know what you're taking with you when you quit, and to where you are
going when you exit?  On the LispM you'd take ALL applications with
you if you actually exited Lisp and you'd exit to a thing called the
front end processor, which was a bit like a cross between Linux LILO
and gdb...  The CLIM designers later tried to formalize the notion of
"exiting the running application", which is at least somewhat better
defined, especially if you can bound it (kind of like catch/throw) by
explicitly specifying the boundary to which you'd like to exit
(sometimes this would exit a bunch of processes or windows, but not
necessarily all processes or windows).
From: Edi Weitz
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <uwtnluopm.fsf@agharta.de>
On Wed, 20 Jul 2005 21:41:20 GMT, Kent M Pitman <······@nhplace.com> wrote:

> Heh, indeed.  And, related to this, people used to ask why there was
> no QUIT function in Lisp and the answer was always: are you sure you
> know what you're taking with you when you quit, and to where you are
> going when you exit?  On the LispM you'd take ALL applications with
> you if you actually exited Lisp and you'd exit to a thing called the
> front end processor, which was a bit like a cross between Linux LILO
> and gdb...

Incidentally, the Lisp Machine had a C compiler, right?  Google found
a message by Barry Margolin where he said that it compiled to machine
code.  But what exactly was the result of a compilation?  A couple of
functions that you could somehow call from Lisp?  And what about the
standard "Hello Word" example wrapped in main(int argc, char **argv)?
How was that supposed to be executed?  Just curious...

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Barry Margolin
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <barmar-FCF5D7.21062820072005@comcast.dca.giganews.com>
In article <·············@agharta.de>, Edi Weitz <········@agharta.de> 
wrote:

> On Wed, 20 Jul 2005 21:41:20 GMT, Kent M Pitman <······@nhplace.com> wrote:
> 
> > Heh, indeed.  And, related to this, people used to ask why there was
> > no QUIT function in Lisp and the answer was always: are you sure you
> > know what you're taking with you when you quit, and to where you are
> > going when you exit?  On the LispM you'd take ALL applications with
> > you if you actually exited Lisp and you'd exit to a thing called the
> > front end processor, which was a bit like a cross between Linux LILO
> > and gdb...
> 
> Incidentally, the Lisp Machine had a C compiler, right?  Google found
> a message by Barry Margolin where he said that it compiled to machine
> code.  But what exactly was the result of a compilation?  A couple of
> functions that you could somehow call from Lisp?  And what about the
> standard "Hello Word" example wrapped in main(int argc, char **argv)?
> How was that supposed to be executed?  Just curious...

I don't remember too much (it's been over a decade since I used it), but 
I think main() was recognized specially, to avoid conflicts between 
different programs being compiled in the same Lisp environment.  When 
you compiled it, you could provide a unique Lisp name to correspond to 
it, and there was some kind of C:RUN-PROGRAM function that was analogous 
to running a program from a Unix shell, in that it would create the 
argc/argv parameters to pass to the function.  And calling exit() would 
effectively do a THROW back to this, so it would exit from the main() 
function, not kill the entire Lisp environment (i.e. shut down the 
machine).

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Kent M Pitman
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <ubr4xezap.fsf@nhplace.com>
Barry Margolin <······@alum.mit.edu> writes:

> > Incidentally, the Lisp Machine had a C compiler, right?  Google found
> > a message by Barry Margolin where he said that it compiled to machine
> > code.  But what exactly was the result of a compilation?  A couple of
> > functions that you could somehow call from Lisp?  And what about the
> > standard "Hello Word" example wrapped in main(int argc, char **argv)?
> > How was that supposed to be executed?  Just curious...
> 
> I don't remember too much (it's been over a decade since I used it), but 
> I think main() was recognized specially, to avoid conflicts between 
> different programs being compiled in the same Lisp environment.  When 
> you compiled it, you could provide a unique Lisp name to correspond to 
> it, and there was some kind of C:RUN-PROGRAM function that was analogous 
> to running a program from a Unix shell, in that it would create the 
> argc/argv parameters to pass to the function.  And calling exit() would 
> effectively do a THROW back to this, so it would exit from the main() 
> function, not kill the entire Lisp environment (i.e. shut down the 
> machine).

Btw, remember too that the answer to the sometimes question of why there's
 ; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Package: CL-USER -*-
rather than [or "in addition to"] using
 (in-package "CL-USER")
is that the LispM had a larger theory of packages that generalized to the
other languages, such that you could get 
 /* -*- Mode: C; Package: MY-C-PACKAGE; -*- */
and it would put the file into the Lisp MY-C-PACKAGE even though the language
processor selected was C.  Ditto for other languages.

It doesn't surprise me that maybe it also special-cased MAIN.

Even if my LispM were powered up for me to check, btw, I couldn't test
this because the "foreign languages" were an additional price product
that I (and many people) didn't buy.  This is another reason that they
are little known of.
From: Edi Weitz
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <u64v56iuq.fsf@agharta.de>
On Wed, 20 Jul 2005 21:06:28 -0400, Barry Margolin <······@alum.mit.edu> wrote:

> I don't remember too much (it's been over a decade since I used it),
> but I think main() was recognized specially, to avoid conflicts
> between different programs being compiled in the same Lisp
> environment.  When you compiled it, you could provide a unique Lisp
> name to correspond to it, and there was some kind of C:RUN-PROGRAM

Ha!  There it is.

And I was using Lisp Machines as an example for an environment where
RUN-PROGRAM doesn't make sense... :)

> function that was analogous to running a program from a Unix shell,
> in that it would create the argc/argv parameters to pass to the
> function.  And calling exit() would effectively do a THROW back to
> this, so it would exit from the main() function, not kill the entire
> Lisp environment (i.e. shut down the machine).

Thanks for the explanation!  Interesting stuff.

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Peter Seibel
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <m2hdepyv8u.fsf@gigamonkeys.com>
Edi Weitz <········@agharta.de> writes:

> On Wed, 20 Jul 2005 21:41:20 GMT, Kent M Pitman <······@nhplace.com> wrote:
>
>> Heh, indeed.  And, related to this, people used to ask why there was
>> no QUIT function in Lisp and the answer was always: are you sure you
>> know what you're taking with you when you quit, and to where you are
>> going when you exit?  On the LispM you'd take ALL applications with
>> you if you actually exited Lisp and you'd exit to a thing called the
>> front end processor, which was a bit like a cross between Linux LILO
>> and gdb...
>
> Incidentally, the Lisp Machine had a C compiler, right?  Google found
> a message by Barry Margolin where he said that it compiled to machine
> code.  But what exactly was the result of a compilation?  A couple of
> functions that you could somehow call from Lisp?  And what about the
> standard "Hello Word" example wrapped in main(int argc, char **argv)?
> How was that supposed to be executed?  Just curious...

And, most important, how did you produce a stand-alone executable from
your C program. ;-)

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Pascal Costanza
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <3k83k2Ft48djU1@individual.net>
Peter Seibel wrote:
> Edi Weitz <········@agharta.de> writes:
> 
>>On Wed, 20 Jul 2005 21:41:20 GMT, Kent M Pitman <······@nhplace.com> wrote:
>>
>>>Heh, indeed.  And, related to this, people used to ask why there was
>>>no QUIT function in Lisp and the answer was always: are you sure you
>>>know what you're taking with you when you quit, and to where you are
>>>going when you exit?  On the LispM you'd take ALL applications with
>>>you if you actually exited Lisp and you'd exit to a thing called the
>>>front end processor, which was a bit like a cross between Linux LILO
>>>and gdb...
>>
>>Incidentally, the Lisp Machine had a C compiler, right?  Google found
>>a message by Barry Margolin where he said that it compiled to machine
>>code.  But what exactly was the result of a compilation?  A couple of
>>functions that you could somehow call from Lisp?  And what about the
>>standard "Hello Word" example wrapped in main(int argc, char **argv)?
>>How was that supposed to be executed?  Just curious...
> 
> And, most important, how did you produce a stand-alone executable from
> your C program. ;-)

Nah, I think C was doomed anyway. ANSI C doesn't define FFI or sockets, 
not mentioning the lack of any standard GUI library. How could you ever 
do anything serious in such a crippled language...


Pascal

-- 
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/
From: Kalle Olavi Niemitalo
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <871x5tt45f.fsf@nntp.kon.iki.fi>
Kent M Pitman <······@nhplace.com> writes:

> you need to find its proper package, where probably
> (symbol-package 'cl-user::run-program) will tell you, and either import
> that package (which will get you other random junk you probably don't know
> about and may not want) or else call the package you get yourself. eg.,
> if it's the system package, then SYSTEM:RUN-PROGRAM ... 

Or import just that one symbol (e.g. with :IMPORT-FROM in
DEFPACKAGE); this may be a good idea if one calls RUN-PROGRAM
from several places and cares about compatibility with CMUCL,
whose EXT:RUN-PROGRAM is much like SBCL's SB-EXT:RUN-PROGRAM.
From: Edi Weitz
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <ur7dtw6up.fsf@agharta.de>
On Wed, 20 Jul 2005 23:29:57 +0300, Emre Sevinc <·····@bilgi.edu.tr> wrote:

>  `-- This function is undefined:
>        RUN-PROGRAM
>
> [...]
>
> Why can't it find the Common Lisp function "run-program"?

RUN-PROGRAM is /not/ a Common Lisp function, it's defined by the
implementation.  Depending on your Lisp it's probably in EXT or SB-EXT
or whatever.  In you package definition you have to USE this package
as well (or use the package-qualified name of the function).

We're probably faster if you paste the whole code that's not working
instead of snippets with "..." in them... :)

Cheers,
Edi.

-- 

Lisp is not dead, it just smells funny.

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: Emre Sevinc
Subject: Re: Let me understand the PACKAGE mechanism
Date: 
Message-ID: <87pstdyzbo.fsf@ileriseviye.org>
Edi Weitz <········@agharta.de> writes:

> On Wed, 20 Jul 2005 23:29:57 +0300, Emre Sevinc <·····@bilgi.edu.tr> wrote:
>
>>  `-- This function is undefined:
>>        RUN-PROGRAM
>>
>> [...]
>>
>> Why can't it find the Common Lisp function "run-program"?
>
> RUN-PROGRAM is /not/ a Common Lisp function, it's defined by the

Whoops! So I misunderstood it.


> implementation.  Depending on your Lisp it's probably in EXT or SB-EXT

It seems to be SB-EXT because when I modified it as:


grammar2dot.lisp
========================================================
(in-package :cl-user)

(defpackage :org.ileriseviye.linear2tree
  (:use 
   :common-lisp
   :sb-ext)
  (:export :produce-tree-output))

(in-package :org.ileriseviye.linear2tree)
.
.
.
=======================================================

and the 

grammar-web.lisp
=====================================================
(in-package :cl-user)

(defpackage :org.ileriseviye.grammar-web
  (:use 
   :common-lisp 
   :net.aserve 
   :net.html.generator
   :org.ileriseviye.linear2tree))

(in-package :org.ileriseviye.grammar-web)
.
.
.
====================================================

everything compiled and ran fine without any problems.


> or whatever.  In you package definition you have to USE this package
> as well (or use the package-qualified name of the function).
>
> We're probably faster if you paste the whole code that's not working
> instead of snippets with "..." in them... :)

You guys are already very fast and to the point, thanks a lot :)


-- 
Emre Sevinc

eMBA Software Developer         Actively engaged in:
http:www.bilgi.edu.tr           http://ileriseviye.org
http://www.bilgi.edu.tr         http://fazlamesai.net
Cognitive Science Student       http://cazci.com
http://www.cogsci.boun.edu.tr