From: ···············@gmail.com
Subject: newbie: command line app using asdf
Date: 
Message-ID: <5639e312-f9bc-4e2e-81ec-1766b05eec34@p25g2000pri.googlegroups.com>
Hello,

I am a lisp newbie and trying to understand asdf better in the context
of
command line apps. I am facing some problems compiling a test file
that
use the sample package that I created.

This is what I have done so far:

Created the following files for a simple package named 'sysint',

sysint.asd:
===========
    [parth:~/training/lisp/sysint]% cat sysint.asd
    (defpackage :sysint-system (:use :common-lisp :asdf))
    (in-package :sysint-system)

    (defsystem sysint
      :name "sysint"
      :version "0.0.1"
      :maintainer "Parth Malwankar <···············@gmail.com>"
      :author "Parth Malwankar <···············@gmail.com>"
      :license "BSD"
      :description "System build and integration facility."
      :long-description ""
      :components
      ((:file "packages")
       (:file "sysint" :depends-on ("packages")))
      :depends-on (:md5 :getopt :cl-fad :cl-ppcre :iterate :binary-
types))

sysint.lisp:
============
    [parth:~/training/lisp/sysint]% cat sysint.lisp
    (in-package #:sysint)

    (defun foo (n) (list n n n n))

    (defun get-argv ()
      #+clisp ext:*args*
      #+sbcl (cdr sb-ext:*posix-argv*)
      #-(or clisp sbcl) (error "get-argv not implemented"))

packages.lisp:
==============
    [parth:~/training/lisp/sysint]% cat packages.lisp
    (in-package #:common-lisp-user)

    (defpackage #:sysint
      (:use #:common-lisp)
      (:documentation "System build and integration facility")
      (:export
        #:foo
        #:get-argv))

test.lisp:
==========
    [parth:~/training/lisp/sysint]% cat test.lisp
    (asdf:operate 'asdf:load-op 'sysint)
    (asdf:operate 'asdf:load-op 'getopt)

    (format t "1]~a~%" (sysint:foo 'a))
    (format t "2]~a~%" (sysint:get-argv))
    (format t "3]~a~%" (getopt:getopt (sysint:get-argv)
'(("c" :required) ("f" :required) ("interact" :required))))

I don't really do much here, just call the functions defined.
After softlinking sysint.asd to ~/.clisp/system/ and adding that to
asdf:*central-registry*, this works fine in the interactive session
with
clisp.

    [1]> (load "test.lisp")
    ;; Loading file test.lisp ...
    ; loading system definition from sysint.asd into #<PACKAGE ASDF0>
    ;;  Loading file sysint.asd ...
    ; registering #<SYSTEM SYSINT #x204A2CF6> as SYSINT
    ;;  Loaded file sysint.asd

    ............... <snip> ....................

    ;;  Loaded file /var/cache/common-lisp-controller/1000/clisp/local/
home/parth/training/lisp/sysint/sysint.fas
    0 errors, 0 warnings
    0 errors, 0 warnings
    1](A A A A)
    2]NIL
    3]NIL
    ;; Loaded file test.lisp
    T
    [2]>

However, if I try to compile this (either with clisp or sbcl) I get
an error saying that 'sysint' package is not defined.

    ;; Loading file /home/parth/.clisprc.lisp ...
    ;; Loaded file /home/parth/.clisprc.lisp
    ;; Compiling file /home/parth/training/lisp/sysint/test.lisp ...
    *** - READ from
           #<INPUT BUFFERED FILE-STREAM CHARACTER
             #P"/home/parth/training/lisp/sysint/test.lisp" @9>
          : there is no package with name "SYSINT"

    0 errors, 0 warnings
    Bye.


After doing some digging around and reading, I realized that using
'eval-when'
around the 'asdf:operate's fixes this.

    (eval-when (:compile-toplevel :load-toplevel :execute)
      (asdf:operate 'asdf:load-op 'sysint)
      (asdf:operate 'asdf:load-op 'getopt))

This does fix the problem, but I am wondering if I am doing this
right.
What is the recommended way of creating a command line application
like
this?

Basically I just want to create a file 'test.fas' so I can do:
    [parth:~/training/lisp/sysint]% clisp test.fas a b c
    1](A A A A)
    2](a b c)
    3](a b c)

Also during when I run the command above, clisp (and sbcl) spits out
a whole lot of compile/load/register etc. messages. Is it possible to
get the command to run silently as shown above?

Much of this is probably lack of understanding on my part. Would
appreciate
any help so I don't go crazy doing this :)

Thanks very much,
Parth

From: Alessio Stalla
Subject: Re: newbie: command line app using asdf
Date: 
Message-ID: <93182b89-5494-48e0-b6e9-e741d6ab708f@8g2000hse.googlegroups.com>
On Jun 8, 5:05 am, ···············@gmail.com wrote:
> Hello,
>
> I am a lisp newbie and trying to understand asdf better in the context
> of
> command line apps. I am facing some problems compiling a test file
> that
> use the sample package that I created.
>
> This is what I have done so far:
>
> Created the following files for a simple package named 'sysint',
>
> sysint.asd:
> ===========
>     [parth:~/training/lisp/sysint]% cat sysint.asd
>     (defpackage :sysint-system (:use :common-lisp :asdf))
>     (in-package :sysint-system)
>
>     (defsystem sysint
>       :name "sysint"
>       :version "0.0.1"
>       :maintainer "Parth Malwankar <···············@gmail.com>"
>       :author "Parth Malwankar <···············@gmail.com>"
>       :license "BSD"
>       :description "System build and integration facility."
>       :long-description ""
>       :components
>       ((:file "packages")
>        (:file "sysint" :depends-on ("packages")))
>       :depends-on (:md5 :getopt :cl-fad :cl-ppcre :iterate :binary-
> types))
>
> sysint.lisp:
> ============
>     [parth:~/training/lisp/sysint]% cat sysint.lisp
>     (in-package #:sysint)
>
>     (defun foo (n) (list n n n n))
>
>     (defun get-argv ()
>       #+clisp ext:*args*
>       #+sbcl (cdr sb-ext:*posix-argv*)
>       #-(or clisp sbcl) (error "get-argv not implemented"))
>
> packages.lisp:
> ==============
>     [parth:~/training/lisp/sysint]% cat packages.lisp
>     (in-package #:common-lisp-user)
>
>     (defpackage #:sysint
>       (:use #:common-lisp)
>       (:documentation "System build and integration facility")
>       (:export
>         #:foo
>         #:get-argv))
>
> test.lisp:
> ==========
>     [parth:~/training/lisp/sysint]% cat test.lisp
>     (asdf:operate 'asdf:load-op 'sysint)
>     (asdf:operate 'asdf:load-op 'getopt)
>
>     (format t "1]~a~%" (sysint:foo 'a))
>     (format t "2]~a~%" (sysint:get-argv))
>     (format t "3]~a~%" (getopt:getopt (sysint:get-argv)
> '(("c" :required) ("f" :required) ("interact" :required))))
>
> I don't really do much here, just call the functions defined.
> After softlinking sysint.asd to ~/.clisp/system/ and adding that to
> asdf:*central-registry*, this works fine in the interactive session
> with
> clisp.
>
>     [1]> (load "test.lisp")
>     ;; Loading file test.lisp ...
>     ; loading system definition from sysint.asd into #<PACKAGE ASDF0>
>     ;;  Loading file sysint.asd ...
>     ; registering #<SYSTEM SYSINT #x204A2CF6> as SYSINT
>     ;;  Loaded file sysint.asd
>
>     ............... <snip> ....................
>
>     ;;  Loaded file /var/cache/common-lisp-controller/1000/clisp/local/
> home/parth/training/lisp/sysint/sysint.fas
>     0 errors, 0 warnings
>     0 errors, 0 warnings
>     1](A A A A)
>     2]NIL
>     3]NIL
>     ;; Loaded file test.lisp
>     T
>     [2]>
>
> However, if I try to compile this (either with clisp or sbcl) I get
> an error saying that 'sysint' package is not defined.
>
>     ;; Loading file /home/parth/.clisprc.lisp ...
>     ;; Loaded file /home/parth/.clisprc.lisp
>     ;; Compiling file /home/parth/training/lisp/sysint/test.lisp ...
>     *** - READ from
>            #<INPUT BUFFERED FILE-STREAM CHARACTER
>              #P"/home/parth/training/lisp/sysint/test.lisp" @9>
>           : there is no package with name "SYSINT"
>
>     0 errors, 0 warnings
>     Bye.
>
> After doing some digging around and reading, I realized that using
> 'eval-when'
> around the 'asdf:operate's fixes this.
>
>     (eval-when (:compile-toplevel :load-toplevel :execute)
>       (asdf:operate 'asdf:load-op 'sysint)
>       (asdf:operate 'asdf:load-op 'getopt))
>
> This does fix the problem, but I am wondering if I am doing this
> right.
> What is the recommended way of creating a command line application
> like
> this?
>
> Basically I just want to create a file 'test.fas' so I can do:
>     [parth:~/training/lisp/sysint]% clisp test.fas a b c
>     1](A A A A)
>     2](a b c)
>     3](a b c)

Hello Parth, welcome to c.l.l.!
As I see it, asdf:operate is not really meant to be called directly,
except in interactive sessions. Usually if your application depends on
other modules which have an asdf system definition (.asd file), you
are supposed to provide an .asd file yourself for your application and
have asdf manage dependencies. Of course this is the general case, it
is up to the programmer adapt it to his/her needs. In your case since
your application is sufficiently small you could avoid writing an .asd
file for it (and the code to have asdf load the system defined in that
file). You can instead rely on a feature most (all?) Lisp
implementations provide: saving the current Lisp image and restoring
it later. Basically, don't put the asdf:operate calls in the test.lisp
file; start a fresh (clisp|sbcl) session and do those calls from the
REPL; then save the image (how to do it depends on the particular
implementation, check its documentation). This way the image will
contain the sysint and getopt systems, and if you reload it (with a
command line switch passed to clisp/sbcl) you'll have those systems
already loaded, and you'll be able to compile test.lisp. In the end,
you should be able to do something like this:

clisp -core /path/to/your/image test.fas a b c

The exact syntax depends on the Lisp implementation you're using.
Saving the Lisp image is a useful technique which can be used in a
variety of situations (since basically you save the entire state of
the Lisp system).

> Also during when I run the command above, clisp (and sbcl) spits out
> a whole lot of compile/load/register etc. messages. Is it possible to
> get the command to run silently as shown above?

Of course, it's probably a command-line switch of clisp/abcl, check
the documentation.

> Much of this is probably lack of understanding on my part. Would
> appreciate
> any help so I don't go crazy doing this :)

Ah, if all the newbies were like you... :) (I'm little more than a
newbie myself, mind you ;)

hth
Alessio
From: ···············@gmail.com
Subject: Re: newbie: command line app using asdf
Date: 
Message-ID: <c390942e-c185-4ddb-9e63-7b9cc4caac6c@w8g2000prd.googlegroups.com>
On Jun 8, 4:58 pm, Alessio Stalla <·············@gmail.com> wrote:
> On Jun 8, 5:05 am, ···············@gmail.com wrote:
>
>
>
> > Hello,
>
> > I am a lisp newbie and trying to understand asdf better in the context
> > of
> > command line apps. I am facing some problems compiling a test file
> > that
> > use the sample package that I created.
>
> > This is what I have done so far:
>
> > Created the following files for a simple package named 'sysint',
>
> > sysint.asd:
> > ===========
> >     [parth:~/training/lisp/sysint]% cat sysint.asd
> >     (defpackage :sysint-system (:use :common-lisp :asdf))
> >     (in-package :sysint-system)
>
> >     (defsystem sysint
> >       :name "sysint"
> >       :version "0.0.1"
> >       :maintainer "Parth Malwankar <···············@gmail.com>"
> >       :author "Parth Malwankar <···············@gmail.com>"
> >       :license "BSD"
> >       :description "System build and integration facility."
> >       :long-description ""
> >       :components
> >       ((:file "packages")
> >        (:file "sysint" :depends-on ("packages")))
> >       :depends-on (:md5 :getopt :cl-fad :cl-ppcre :iterate :binary-
> > types))
>
> > sysint.lisp:
> > ============
> >     [parth:~/training/lisp/sysint]% cat sysint.lisp
> >     (in-package #:sysint)
>
> >     (defun foo (n) (list n n n n))
>
> >     (defun get-argv ()
> >       #+clisp ext:*args*
> >       #+sbcl (cdr sb-ext:*posix-argv*)
> >       #-(or clisp sbcl) (error "get-argv not implemented"))
>
> > packages.lisp:
> > ==============
> >     [parth:~/training/lisp/sysint]% cat packages.lisp
> >     (in-package #:common-lisp-user)
>
> >     (defpackage #:sysint
> >       (:use #:common-lisp)
> >       (:documentation "System build and integration facility")
> >       (:export
> >         #:foo
> >         #:get-argv))
>
> > test.lisp:
> > ==========
> >     [parth:~/training/lisp/sysint]% cat test.lisp
> >     (asdf:operate 'asdf:load-op 'sysint)
> >     (asdf:operate 'asdf:load-op 'getopt)
>
> >     (format t "1]~a~%" (sysint:foo 'a))
> >     (format t "2]~a~%" (sysint:get-argv))
> >     (format t "3]~a~%" (getopt:getopt (sysint:get-argv)
> > '(("c" :required) ("f" :required) ("interact" :required))))
>
> > I don't really do much here, just call the functions defined.
> > After softlinking sysint.asd to ~/.clisp/system/ and adding that to
> > asdf:*central-registry*, this works fine in the interactive session
> > with
> > clisp.
>
> >     [1]> (load "test.lisp")
> >     ;; Loading file test.lisp ...
> >     ; loading system definition from sysint.asd into #<PACKAGE ASDF0>
> >     ;;  Loading file sysint.asd ...
> >     ; registering #<SYSTEM SYSINT #x204A2CF6> as SYSINT
> >     ;;  Loaded file sysint.asd
>
> >     ............... <snip> ....................
>
> >     ;;  Loaded file /var/cache/common-lisp-controller/1000/clisp/local/
> > home/parth/training/lisp/sysint/sysint.fas
> >     0 errors, 0 warnings
> >     0 errors, 0 warnings
> >     1](A A A A)
> >     2]NIL
> >     3]NIL
> >     ;; Loaded file test.lisp
> >     T
> >     [2]>
>
> > However, if I try to compile this (either with clisp or sbcl) I get
> > an error saying that 'sysint' package is not defined.
>
> >     ;; Loading file /home/parth/.clisprc.lisp ...
> >     ;; Loaded file /home/parth/.clisprc.lisp
> >     ;; Compiling file /home/parth/training/lisp/sysint/test.lisp ...
> >     *** - READ from
> >            #<INPUT BUFFERED FILE-STREAM CHARACTER
> >              #P"/home/parth/training/lisp/sysint/test.lisp" @9>
> >           : there is no package with name "SYSINT"
>
> >     0 errors, 0 warnings
> >     Bye.
>
> > After doing some digging around and reading, I realized that using
> > 'eval-when'
> > around the 'asdf:operate's fixes this.
>
> >     (eval-when (:compile-toplevel :load-toplevel :execute)
> >       (asdf:operate 'asdf:load-op 'sysint)
> >       (asdf:operate 'asdf:load-op 'getopt))
>
> > This does fix the problem, but I am wondering if I am doing this
> > right.
> > What is the recommended way of creating a command line application
> > like
> > this?
>
> > Basically I just want to create a file 'test.fas' so I can do:
> >     [parth:~/training/lisp/sysint]% clisp test.fas a b c
> >     1](A A A A)
> >     2](a b c)
> >     3](a b c)
>
> Hello Parth, welcome to c.l.l.!
> As I see it, asdf:operate is not really meant to be called directly,
> except in interactive sessions. Usually if your application depends on
> other modules which have an asdf system definition (.asd file), you
> are supposed to provide an .asd file yourself for your application and
> have asdf manage dependencies. Of course this is the general case, it
> is up to the programmer adapt it to his/her needs. In your case since
> your application is sufficiently small you could avoid writing an .asd
> file for it (and the code to have asdf load the system defined in that
> file). You can instead rely on a feature most (all?) Lisp
> implementations provide: saving the current Lisp image and restoring
> it later. Basically, don't put the asdf:operate calls in the test.lisp
> file; start a fresh (clisp|sbcl) session and do those calls from the
> REPL; then save the image (how to do it depends on the particular
> implementation, check its documentation). This way the image will
> contain the sysint and getopt systems, and if you reload it (with a
> command line switch passed to clisp/sbcl) you'll have those systems
> already loaded, and you'll be able to compile test.lisp. In the end,
> you should be able to do something like this:
>
> clisp -core /path/to/your/image test.fas a b c
>

Wow. Now why didn't I think of this.
Probably too much of C ... :)

> The exact syntax depends on the Lisp implementation you're using.
> Saving the Lisp image is a useful technique which can be used in a
> variety of situations (since basically you save the entire state of
> the Lisp system).
>
> > Also during when I run the command above, clisp (and sbcl) spits out
> > a whole lot of compile/load/register etc. messages. Is it possible to
> > get the command to run silently as shown above?
>
> Of course, it's probably a command-line switch of clisp/abcl, check
> the documentation.
>
> > Much of this is probably lack of understanding on my part. Would
> > appreciate
> > any help so I don't go crazy doing this :)
>
> Ah, if all the newbies were like you... :) (I'm little more than a
> newbie myself, mind you ;)
>
> hth
> Alessio

Thanks Alessio / Vanekl. This works perfectly.

    [parth:~/training/lisp/sysint]% clisp
    [1]> (asdf:oos 'asdf:load-op 'sysint)
    ; loading system definition from sysint.asd into #<PACKAGE ASDF0>
    ................... <snip> ........................
    ; loading system definition from /usr/share/common-lisp/systems/
md5.asd into #<PACKAGE
    ;   ASDF0>
    ; registering #<SYSTEM MD5 #x204AAB8E> as MD5
    NIL
    [2]> (asdf:oos 'asdf:load-op 'getopt)
    NIL
    [3]> (ext:saveinitmem)
    5270024 ;
    1317506
    [4]>
    [parth:~/training/lisp/sysint]% clisp -M lispinit.mem test.lisp a
b c
    1](A A A A)
    2](a b c)
    3](a b c)
    [parth:~/training/lisp/sysint]% clisp -M lispinit.mem -c
test.lisp
    [parth:~/training/lisp/sysint]% cl -M lispinit.mem test.fas a b c
    1](A A A A)
    2](a b c)
    3](a b c)
    [parth:~/training/lisp/sysint]%
From: vanekl
Subject: Re: newbie: command line app using asdf
Date: 
Message-ID: <g2gja4$8sf$1@aioe.org>
···············@gmail.com wrote:
snip
> What is the recommended way of creating a command line application
> like
> this?

in clisp, you can create a script file by putting this in a .lisp file,

#!/usr/bin/clisp -q
(format t "hi!~%")

[http://clisp.cons.org/impnotes.html#quickstart]
[http://clisp.cons.org/clisp.html#opt-verbose]

Remember to,
   chmod u+x thefile.lisp

Run it:
   ./thefile.lisp


OR, you could save a lisp image as an executable:

(defun saveimage()
   (saveinitmem "hi.exe" :executable t :init-function 'main :quiet t :norc t))

(defun main()
   (format t "hi~%")
   (exit))

[http://clisp.cons.org/impnotes.html#image]
[sbcl: sb-ext:save-lisp-and-die]


> Basically I just want to create a file 'test.fas' so I can do:
>     [parth:~/training/lisp/sysint]% clisp test.fas a b c
>     1](A A A A)
>     2](a b c)
>     3](a b c)
> 
> Also during when I run the command above, clisp (and sbcl) spits out
> a whole lot of compile/load/register etc. messages. Is it possible to
> get the command to run silently as shown above?

[note the -q and :quiet options above]

(defun toggle-print (&optional (on t))
   (setf *compile-print*   on
	*compile-verbose* on
	*load-print*      on
	*load-verbose*    on))

;; you can use this if you want to cut down on some of the verbosity.
(toggle-print nil)


for sbcl, also see
http://www.sbcl.org/manual/Controlling-Verbosity.html#Controlling-Verbosity


> Much of this is probably lack of understanding on my part. Would
> appreciate
> any help so I don't go crazy doing this :)
> 
> Thanks very much,
> Parth