lispcookbook / cl-cookbook Goto Github PK
View Code? Open in Web Editor NEWThe Common Lisp Cookbook
Home Page: http://lispcookbook.github.io/cl-cookbook/
License: Other
The Common Lisp Cookbook
Home Page: http://lispcookbook.github.io/cl-cookbook/
License: Other
Hello --
The documentation on using something like CLIM is
overwhelming. We need to simple tips on building GUIs,
simple examples.
Please choose a simple a Libre Software solution.
Thank you.
synthespian
[http://sourceforge.net/p/cl-cookbook/feature-requests/4/]
maybe the document found at
http://www.ai.sri.com/~pkarp/loop.html
is fine as an answer to request 766293 ?
[John Thingstad @ http://sourceforge.net/p/cl-cookbook/feature-requests/22/]
Regarding the question Accessing Enviroment Variables
in Interfacing with your OS:
gut reaction: i found the answer scary.
hopefully costructive criticizem(sp?): CLOCC provides
getenv, which will work on more implementations than
the answer offered in the cookbook. I really believe
that it is important to point out already existing
solutions when they exist. CLOCC's getenv is setfable,
which, IMO, is more "lispy" than calling getenv with
one argument to get and two to set.
since CLOCC provides so many answers, maybe someone (i
will try when i have time) will just sit down and make
up the questions? if nothing else it will add a little
bulk to the cookbook in those areas where lisp seems ot
be laking (os interface/net "stuff")
p.s. - thank you for the cookbook.
[http://sourceforge.net/p/cl-cookbook/feature-requests/1/]
I think everybody's moved on to SLIME and SWANK.
[http://sourceforge.net/p/cl-cookbook/bugs/18/]
File locking is not in the Common Lisp standard. However, the following macro should work in most cases:
(defmacro with-file-lock ((path &key interval) &body body)
"Get an exclusive lock on a file. If lock cannot be obtained, keep
trying after waiting a while"
(let ((lock-path (gensym))
(lock-file (gensym)))
`(let ((,lock-path (format nil "~a.lock" (namestring ,path))))
(unwind-protect
(progn
(loop
:for ,lock-file = (open ,lock-path :direction :output
:if-exists nil
:if-does-not-exist :create)
:until ,lock-file
:do (sleep ,(or interval 0.1))
:finally (close ,lock-file))
,@Body)
(ignore-errors
(delete-file ,lock-path))))))
another solution is calling the underlying system locking facilities, e.g. on SBCL you can use sb-posix:fcntl.
[Giovanni Gigante @ http://sourceforge.net/p/cl-cookbook/patches/8/]
Pattern matching should discuss optima and regular expressions should discuss cl-ppcre
Using Xemacs 2.4.13 on WinXP, with ILISP 5.12 and CLISP
2.30. Can start CLISP in inferior process, but get
error that CLISP cannot find init files (e.g.
ilisp-pkg.lisp). Appears to be due to fact that file
name being passed to CLISP includes '' as path
separator, instead of '/'. Have done some research in
ilisp-snd.el and ilisp-hi.el, but have not figured out
how to prevent file name problem.
[Alexander Stockdale @ http://sourceforge.net/p/cl-cookbook/feature-requests/13/]
Discussion:
Nobody/Anonymous:
Are you using the Win32 version of CLISP or are you running
a Unix-y version under cygwin? I think one difference is in
the way path separators are handled. -win32.zip, not tar.gz.
That's just a vague recollection, hope it works.
Alexander Stockdale:
In answer to the question, I am using the win32 version of
CLISP. Further update: I think I have solved the problem (or
at least, found a fix). I modified file-name-hack in ilisp-hi.el
to check for system-type of 'windows-nt, and ilisp-dialect
of 'clisp-hs. If both conditions satisfied, I use replace-in-
string to change "" to "/".
This may not be the most elegant fix, but it works, and at
least the changes are localized to a function that already
kludges filenames.
Alexander Stockdale:
Attaching a copy of a modified ilisp-hi.el with hack so that
init filenames can be handled by clisp.
Alexander Stockdale:
Modified ilisp-hi.el with hack so that init filenames are passed to CLISP in a format it can handle.
http://sourceforge.net/p/cl-cookbook/feature-requests/_discuss/thread/82f87c3e/39b1/attachment/ilisp-hi.el / https://gist.github.com/chuchana/82b6dcb4f5cdf3641906
I saw the articles on how to implement a Windows
window in LISP but, how could I implement a non-
formatting command window in C++. Make a simple edit
box that I could type in (print "hello lisp") and have
CLISP run it and print out in another edit box.
In other words I want to use CLISP in my for "run time
user stuff" in a afx C++ window.
[http://sourceforge.net/p/cl-cookbook/feature-requests/9/]
As someone curious about CL, I heard that one can compile a form and be notified at compile time of type errors. So CL has types ? How that ? How do they compare to Python or to Haskell ? Because we are in a cookbook I'd like many code samples.
As a practicing learner, I saw declare
and sometimes the
. I'd like a quick reference. I'd like to see how Slime will warn me, and if and when it is useful.
a first search:
Strings aren't complete without a regular expression
engine!
I think it would be a great service to mention one of
them, I personally use cl-ppcre (
http://www.weitz.de/cl-ppcre/ ) which has completely
eclipsed all other string handling for me, it's really
a savior and bitch'in fast. :-)
Yes, I'll volunteer to write it too.
[Heow Eide-Goodman @ http://sourceforge.net/p/cl-cookbook/feature-requests/14/]
I stumbled across this while looking for an answer to a
poignant hash-table question. Namely, how does one
make a hash-table whose entries are CLOS objects? The
spec only requires that hash-tables accept eq, eql,
equal, equalp as tests. Unfortunately, these are all
equivalent to EQ when applied to CLOS objects. And
none are generic functions. An answer to this question
would sure be helpful!
If I find a good one, I'll submit it.
Cheers,
R
[Robert P. Goldman @ http://sourceforge.net/p/cl-cookbook/feature-requests/5/]
Nobody/Anonymous:
I think you might be confusing CLOS objects with the ability to use GFs, so I want to ask: do you want a
hash-table whose equality test is a GF, or a table which distinguishes CLOS objects by some means other than
the four equality tests you (correctly) listed?
If it's the first of these, then you're stuck. If it's the other you could write some code to extact the information you
want out of a CLOS structure into - say - a list in such a form that equal would serve you.
Hash-tables have to be restricted in this way, otherwise they'd be too inefficient to be usable. Maybe you shouldn't
be using a hash-table?
What are you trying to achieve? What would your equality test look like?
Robert P. Goldman:
I wasn't confusing CLOS objects with the ability to use
Generic Functions as a test in a hash table. But there is
an obvious connection: since none of the existing equality
tests are sufficient to test CLOS objects, a generic
function is a logical way to implement an
equality/equivalence test for CLOS objects in a hash table.
Actually, it turns out that I'm NOT stuck. For CMUCL, one
can make special-purpose hash tables using the (not
well-documented) function define-hash-table-test, which
allows you to provide a special hash-function/equality test
combination for new kinds of hash tables.
[I'm not sure what the situation is for Allegro, since I
don't have a license any more, but I'm pretty sure I was
able to make hash tables of objects there.]
The CMUCL solution is actually just the Right Thing, because
it allows you to provide two pretty simple pieces of
information, and then use the hash-table functions as they
are. Much better than having to do all kind of monkeying
around with making lists out of objects, handling buckets
and collisions yourself, etc.
After all, if I wanted to write C, I could write C. I'm
writing CL because (1) I need to do rapid prototyping and
experiment with different data structures and (2) my time is
more important than my Athlons'! So, with all due respect,
I would prefer to be the judge of whether my hash table is
going to be too inefficient to be usable. Not only do I
want to use CL instead of C, I want to use CL instead of
Pascal, the language that nags me! :-)
I could write up instructions about how to use hash-tables
for more ambitious things in CMUCL, but probably I would be
better off offering to help fix the CMUCL documentation for
this.
Nobody/Anonymous:
Implementation dependant. In CMUCL, do something like
(ext:define-hash-table-test 'foo #'foo-t #'foo-h), and then
(make-hash-table :test 'foo) makes a hash table that uses
(foo-t x y) to compare two items, and (foo-h x) to generate
the hash value. [Of course, you have to make sure that
(foo-t x y) implies (= (foo-h x) (foo-h y))]
GitHub Pages allows us to turn this into a Jekyll project and build automatically on each commit.
The link to pascal constanza's guide is broken, you can find the current version here: http://p-cos.net/lisp/guide.html
[http://sourceforge.net/p/cl-cookbook/bugs/19/]
It would be great to have a cookbook chapter on
mathematics.
[http://sourceforge.net/p/cl-cookbook/feature-requests/19/]
Since mobile platforms are so popular nowdays I think that a chapter on developing lisp applications for Android and iOS would be a great improvement.
Something like a Common Lisp for mobile HOWTO.
For this I'd personally use https://stackoverflow.com/a/42838145/1506338 (and I'm very eager in writing it).
There would be examples, what's lacking, how to quickstart everything, references to libraries found in the Awesome list.
Hi, How do I set proxy host and port in CLISP? I tried setting HTTP-PROXY but it didn't give any results for me.
[http://sourceforge.net/p/cl-cookbook/feature-requests/24/]
Is there a library of functions that operate on abstract
set and list types with pluggable implementations, like
hash-sets, linked-lists, array-lists etc?
Manuel Simoni ([email protected])
Nobody/Anonymous:
There's at least AP5 at http://www.ap5.com/ , but that is
generalized to the relational level of semantics. I believe that
there is also an abstract types toy library, but I can't locate it at
the moment; perhaps it's part of CLOCC.
is there any kind of a roadmap with the list of issues that should be addressed - like reformatting from HTML to some other format to make it work nicely with githib books?
ideas how to improve contents of the book?
A "Database connectivity" section should be added using
the CLSQL library (by the UFFI author) before any
implementation specific methods.
[Frederic Brunel @ http://sourceforge.net/p/cl-cookbook/feature-requests/3/]
In the 'Dates and Times' example of using the functions in a program, the keyword 'date' is used instead of the more appropriated 'day'.
[http://sourceforge.net/p/cl-cookbook/bugs/21/]
The chapter on macros at one point defines a simple
macro. Then the following excersise is given:
"Exercise: Try writing the new version of the macro
without using backquote. If you can't do it, you have
done the exercise correctly, and learned what backquote
is for!"
Why I'm supposed not to be able to convert the macro?
Drew McDermott: If you can do it without backquote, that's great! It's just an annoyingly
difficult chore, so it shows you why backquote is so useful.
[http://sourceforge.net/p/cl-cookbook/feature-requests/21/]
We have Markdown for a reason.
I realize that the CL Cookbook appears to be moribund, but just in case someone does care, the ostensibly portable GETENV implementation at http://cl-cookbook.sourceforge.net/os.html is rather out of date and is missing support for several major implementations.
Here's a replacement implementation that has been correctly conditionalized for and checked/tested with all current open-source Common Lisp implementations of note:
https://github.com/dryproject/snippets/blob/master/common-lisp/getenv.lisp
It's placed in the public domain, so feel free to copy and paste it verbatim.
[Arto Bendiken @ http://sourceforge.net/p/cl-cookbook/bugs/23/]
It would be very helpful to have even a very simple example
of an efficient (again simple) log parser.
Looking at cl-httpd's common-log-parser isn't helpful
at all, because
it's quite complex..
Ross Lonstein:
Log parsing is just string parsing and file manipulation.
The below can be used in place of awk for the very simple case of extracting columns from the
interesting lines of a file (those matching a simple string):
(defun split (delim line)
"Return a list of subsequences separated by a one character delimiter, delim itself is not returned"
(loop :for mark = 0 :then (1+ point)
:for point = (position delim line :start mark)
:collect (subseq line mark point)
:while point))
(defun splitcols (columns file &key (delim #\Space) grep)
"Iterate over the lines of a file, returning the specified columns.
If :grep is supplied only lines containing that string will be returned."
(with-open-file (s file)
(loop :for line = (read-line s nil)
:while line
:when (or (eq grep nil) (search grep line))
:collect (loop :with chunks = (split delim line)
:for c :in columns
:collect (elt chunks c)))))
This is not particularly efficient. On my machine, comparing awk (including startup) to
SBCL 1.0.18 (not including startup) and sinking the output shows awk to be more than 3x
faster.
[http://sourceforge.net/p/cl-cookbook/feature-requests/11/]
I'm just getting into lisp, and I was very surprised by
the lack of a function in the ANSI standard for
replacing subsections of vectors (strings) with other
vectors. In C#, you can do something like
mySqlQuery.Replace("'", "\'")
to make it safe for inserting into a DB, and quoting
like that is something you do in tons of places in web
programming. So I think you should include a function
for replacing things in vectors like this. I found this
function on http://www.lisp-p.org/lht/, by Gene Michael
Stover (it was called "string-replace-all-faster" there).
(defun string-replace-all (source old new)
"Replace all occurrences in 'source' of 'old' with
'new'."
(do ((newlen (length new))
(i (search old source)
(search old source :start2 (+ i newlen))))
((null i) source)
(setq source
(concatenate 'string
(subseq source 0 i)
new
(subseq source (+ i newlen))))))
I haven't gotten his permission for anything, I just
found it. I modified the doc string a bit, and I
changed the order and name of the arguments, and the
name of the function.
Maybe there's a library of basic string functions
somewhere you could link to on the string page.
[Chris Capel @ http://sourceforge.net/p/cl-cookbook/feature-requests/16/]
UFFI is an abstraction layer over all well-known Common
Lisp FFI implementations. It may be interessting to add
an example using this layer in the FFI section of the
CL Cookbook.
[Frederic Brunel @ http://sourceforge.net/p/cl-cookbook/feature-requests/2/]
The step-by-step HOWTO set up a Common Lisp IDE,
centering on several modes of Emacs interaction, with
multiple options for CL implementations on Windows
(and Mac) is excellent. But I'm hoping to use Lisp and
Emacs as my bridge away from Windows -- how about CygWin?
What I would really like would be a similarly detailed
and keystroke-specific and explicit HOWTO that might
help foster my slow transition to Unix, via the
discipline of first mastering Emacs and Common Lisp in
their preferred POSIX environment. (Of course I should
just bite the bullet and dive in with Debian, for its
easily apt-getable CL packages, but with a 32 MB
Pentium 100 MHz running Allegro Common Lisp and Emacs,
I question whether any recent Linux could even run what
I need. Bash is another matter, I know I need to learn
that, too, and I'm happy to learn the shell while
looking for a job to finance a hardware upgrade. I
have another hand-me-down machine, with 64 MB RAM and a
whopping 4 GB free, so I may be able to squeeze
Libranet on it and have a newbie-friendly Debian
install running icewm on 64 MB. That may be able to
run Emacs and CLisp and perhaps CMUCL as well, with or
without X. Point is: CygWin is still relevant for the
hardware and financially challenged, not to mention
those in MS shops, and, frankly, insecure but wannabe
newbies, even in this day of Knoppix. And the Cygwin
documentation is not what Windozed users need to make
the break.)
I've tried with CygWin -- setup.exe is easy enough --
and can run bash and Emacs and CLisp as well, but I
simply can't understand getting X to work (and don't
think I should have to work this hard to get a
scrollbar) and I remain baffled on the numerous options
for getting Emacs and various implementations of CL to
talk to one another. This very uninteresting setup (to
me -- I appreciate the fascination it may present to
others) is all totally new and these installation
snafus are frankly a shitty introduction to a language
and programming environment that come highly touted by
many people I respect. Perhaps someone might rewrite
the following exemplary HOWTO for those who want to
sample multiple open source CL implementations and
Emacs modes (including SLIME) on CygWin, or probably
not at all.
http://cl-cookbook.sourceforge.net/windows.html#Mac%20OS%20X%20Setup%20Instructions
Thank you. Yet another Lisp newbie.
[http://sourceforge.net/p/cl-cookbook/feature-requests/18/]
The process/threads page (https://lispcookbook.github.io/cl-cookbook/process.html) only refers to LispWorks:
refers only to LispWorks. It has been tested on LispWorks for Windows Professional version 4.2.6 running on Windows NT (SP 6). All the examples below (apart from those few which require resaving the lisp image) should work without difficulty on the (free) Personal edition running under either Linux or Windows.
Your mileage may vary. I will add “support” for other implementations and operating systems to this page later, if I have the time and access to the appropriate materials.
it doesn't mention the multiplatform Bordeaux Threads library.
Link to „Lisp and Elements of Style” by Nick Levine on main page is dead.
Probably actual one is http://www.nicklevine.org/declarative/lectures/
[http://sourceforge.net/p/cl-cookbook/bugs/20/]
do you have any idea how to configure the GNU XEmacs
for WINDOWS to work with the CL programs?
I personally use xemacs-21.4.6.
Thanks.
Alexander Stockdale:
I am in the process of trying to set up CLISP to work with
ILISP in Xemacs. The cookbook is helpful, but the .emacs
file seems to be GNU emacs specific. I've used the
instructions as a guide, rather than following them
slavishly. At this point, my only problem is that the init
files (ilisp-pkg.lisp, cl-ilisp.lisp, cl-chs-init.lisp) are
not being loaded properly by CLISP, apparently because the
'/' character in the ILISP directory path is being changed
to a '', and subsequently dropped by CLISP. I'm
experimenting to see where the character translation is
happening, and how to prevent it. Any advice/solutions welcome.
[http://sourceforge.net/p/cl-cookbook/feature-requests/6/]
and thus lacking a TOC, a title and the link to come back to the index.
After #35 is done, we start turning the HTML into Markdown.
This is pretty extensive so any help is appreciated.
http://cl-cookbook.sourceforge.net/os.html would be more user-friendly if the package name was noted for POSIX-ARGV (I believe it's in SB-EXT)
[http://sourceforge.net/p/cl-cookbook/bugs/22/]
Can SomeOne explain me How to
Configure Xemacs for Clisp. I found The Article
"Setting up an IDE with Emacs on Windows"
But this doesnt wok witk my Xemacs
I suppose this Article works only wirth Emacs.
Thank You for your Help
Alexander Stockdale:
The sample .emacs file doesn't work, but the instructions in
general are correct. I made some progress by using the
ilisp.emacs file in the ilisp directory (look in
xemacs-packages/lisp) as a template for my init.el file.
Still having problems (as described elsewhere) with CLISP
not loading the init files properly.
[ek @ http://sourceforge.net/p/cl-cookbook/feature-requests/12/]
When trying to load the .emacs sample file the
following message appears:
Fatal error: Cannot redeclare get_pref_language_array
() (previously declared
in /space_3/mandragor/www/docs/includes/language_file.p
hp:3)
in /space_3/mandragor/www/docs/includes/language_file.p
hp on line 3
[http://sourceforge.net/p/cl-cookbook/bugs/15/]
https://lispcookbook.github.io/cl-cookbook/systems.html
seems like a miss :S
ASDF3 tutorial/best practices: https://gitlab.common-lisp.net/asdf/asdf/blob/master/doc/best_practices.md
such as Prove, according to http://eudoxia.me/article/common-lisp-sotu-2015#testing
Furthermore where is RT's doc ? Old and messy links on the given http://www.cliki.net/RT
Please add a note of the Lisp equivalent of the C select() function to
the Sockets Section.
[http://sourceforge.net/p/cl-cookbook/feature-requests/15/]
After #35 is done, improve the CSS.
I think the * is a bit difficult to separate from code because it means multiplication, especially to newbies. SLIME which is favoured by pretty much everyone 2015AD for lisping has CL-USER> prompt on REPL and there is no way that gets mixed.
Review use of CLOCC, determine if it's appropriate, migrate to Quicklispy systems where possible and appropriate.
A section on using the loop macro would be nice.
[http://sourceforge.net/p/cl-cookbook/feature-requests/10/]
The master
branch of the cl-cookbook should have a CD to gh-pages so no manual deploys are needed.
About functions returning functions –
The handbook on CLISP says : «In Common Lisp, as opposed to Scheme, it is not possible that the car of the compound form to be evaluated is an arbitrary form. If it is not a symbol, it must be a lambda expression.» This explanation corresponds to my experience in trying to code in Lisp.
Nevertheless some Lisp code seems to override this limitation. Maxima is written in Lisp and uses internally some code like « ((mlist simp) 1 2 7 ((mplus simp) $X $Y)) ». Here, the car of a compound form is not a lambda expression but an internal form whose car is an additional symbol defined by Maxima. This internal form evaluates therefore to a function which can be used directly, like a function symbol, without the use of a funcall or apply operator.
I am just curious to understand why and how.
[Silvain Dupertuis @ http://sourceforge.net/p/cl-cookbook/support-requests/2/]
Hi,
Two things as detailed below.
Cheers, Doug
ps: I am new to this, so I hope I'm making some sense
to you :)
1st Thing:
I have installed Emacs, ILISP and CL. Everything look OK
but i get a couple of errors when i start up ILISP in
Emacs (by pressing F5).
Here are all the messages. You can see the errors at
the end.
So, all the obvious questions - Should I be worried
about these errors? What do I need to do to do to fix
them? Why is ILISP initializing twice?
(C:\bin\emacs-21.3\bin\emacs.exe)
Loading regexp-opt...done
Loading image...done
Loading cl-macs...done
Loading c:/home/.recentf...done
Loading pc-select...done
Loading delsel...done
Loading paren...done
Loading advice...done
Reading directory c:/home/...done
For information about the GNU Project and its goals,
type C-h C-p.
Loading ilcompat...
Loading ilfsf21...done
Loading ilcompat...done
Loading comint-ipc...done
Loading extra/hyperspec...
Use C-u M-x make-directory RET RET to create
directory and its parents
Loading extra/hyperspec...done
Loading extra/cltl2...done
Loading ilisp-all.elc...
Loading cl-seq...done
Loading ilisp-all.elc...done
Loading menu interface.
'ilisp-enable-cl-easy-meny-p' is t
Loading ilisp-cl-easy-menu (source)...done
Loading ild...done
Loading ilisp-imenu...done
Loading outline...
Loading easy-mmode...done
Loading outline...done
Started initializing ILISP [2 times]
Aborted commands
error in process filter: file-name-hack: Symbol's function
definition is void: replace-in-string
error in process filter: Symbol's function definition is
void: replace-in-string
Set clisp-hs's directory to c:/home/
2nd thing:
Is the following normal?
Starting c:/bin/clisp-2.33.1/full/lisp.exe -B c:/bin/clisp-
2.33.1/full/ -M c:/bin/clisp-2.33.1/full/lispinit.mem -ansi -
q ...
ILISP V5.12.0 Use M-x ilisp-bug for problems and
suggestions.
;; Loading file C:\home_clisprc.lisp ...
;; Loaded file C:\home_clisprc.lisp
[1]>
[2]> (defvar"at this point i can't enter a space and get -
-> file-name-hack: Symbol's function definition is void:
replace-in-string, and now having added this comment is
can continue typing e.g." x 1)
*** - DEFVAR: non-symbol "at this point i cant't enter a
space and get --> file-name-hack: Symbol's function
definition is void: replace-in-string, and now having
added this comment is can continue " cannot be a
variable (Obviously)
Break 3 [8]>
"if i go to a blank line things are ok"
Break 3 [8]>
(defvar x 1)
X
Break 3 [8]>
x
1
Break 3 [8]>
[http://sourceforge.net/p/cl-cookbook/feature-requests/17/]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.