lisp | Lisp In Small Pieces на русском языке | Chat library
kandi X-RAY | lisp Summary
kandi X-RAY | lisp Summary
Это перевод на русский язык «широко известной в узких кругах» книги Кристиана Кеннека «Les Langages Lisp» (aka Lisp in Small Pieces). Книга затрагивает основы построения интерпретаторов и компиляторов Лиспа (в первую очередь его диалекта Scheme), а также разнообразие вариантов понимания семантики его конструкций и возможностей вроде окружений, замыканий, исключений, продолжений, рефлексии и макросов.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of lisp
lisp Key Features
lisp Examples and Code Snippets
Community Discussions
Trending Discussions on lisp
QUESTION
ANSWER
Answered 2021-Jun-15 at 04:28This can be found here in the HyperSpec: 17.2.1 Satisfying a Two-Argument Test. A list of sequence functions, including member
, find
, and position
, is given. These functions take a two-argument :test
or :test-not
argument.
If neither a
:test
nor a:test-not
argument is supplied, it is as if a:test
argument of#'eql
was supplied.
QUESTION
I made a lisp code that transforms a list of numbers into a tree. The rules of the tree are that the value of the left child node should always be smaller than the value of its parent node and the value of the right child node should always be higher than the value of its parent node.
Here is my lisp code:
...ANSWER
Answered 2021-Jun-13 at 15:55You are modifying list
but not returning it.
Here is what you need to do:
QUESTION
I'm using SBCL 2.0.1.debian and Paul Graham's ANSI Common Lisp to learn Lisp.
Right in Chapter 2 though, I'm realizing that I cannot use setf
like the author can! A little googling and I learn that I must use defvar
or defparameter
to 'introduce' my globals before I can set them with setq
!
Is there any way to avoid having to introduce globals via the defvar
or defparameter
, either from inside SBCL or from outside via switches? Do other Lisp's too mandate this?
I understand their value-add in large codebases but right now I'm just learning by writing smallish programs, and so am finding them cumbersome. I'm used to using globals in other languages, so don't necessarily mind global- / local-variable bugs.
...ANSWER
Answered 2021-Jun-11 at 11:29If you are writing programs, in the sense of things which have some persistent existence in files, then use the def*
forms. Top-level setf
/ setq
of an undefined variable has undefined semantics in CL and, even worse, has differing semantics across implementations. Typing defvar
, defparameter
or defconstant
is not much harder than typing setf
or setq
and means your programs will have defined semantics, which is usually considered a good thing. So no, for programs there is no way to avoid using the def*
forms, or some equivalent thereof.
If you are simply typing things at a REPL / listener to play with things, then I think just using setf
at top-level is fine (no-one uses environments where things typed at the REPL are really persistent any more I think).
You say you are used to using globals in other languages. Depending on what those other languages are this quite probably means you're not used to CL's semantics for bindings defined with def*
forms, which are not only global, but globally special, or globally dynamic. I don't know which other languages even have CL's special / lexical distinction, but I suspect that not that many do. For instance consider this Python (3) program:
QUESTION
I am reading the book Object Oriented Programming in Common Lisp from Sonja Keene.
In chapter 2, the author says:
The procedure for determining which methods to call and then calling them is called generic dispatch. It happens automatically whenever a generic function is called.
This reminds me of the Dynamic Dispatch definition which is (according to Wikipedia):
Dynamic dispatch is the process of selecting which implementation of a polymorphic operation to call at run time. It is commonly employed in, and considered a prime characteristic of, object-oriented programming languages and systems.
Unfortunately, the wikipedia does not have an entry about generic dispatch.
Thus, I would like ask:
1 - Are dynamic dispatch and generic dispatch basically the same thing? What are the similarities?
2 - And what are the differences? Is dynamic dispatch some sort of subset of generic dispatch due to the flexibility of CLOS?
...ANSWER
Answered 2021-Jun-09 at 06:32Yes, dispatch in CLOS is also dynamic (this is also called late binding).
No, dynamic and generic dispatch are not the same thing, because the words generic and dynamic answer different questions.
The point that the word dynamic makes is that the decision about which method(s) to call is made at run time. The contrast to that would be static dispatch (which some would not call dispatch but overloading), where the decision is made at compile time.
The point that the word generic makes is that the decision about which method(s) to call is made on the basis of the type of all (required) arguments. The methods are attached to the generic function. The contrast to that would be class based dispatch, where the decision is made only on the class of the first argument and the methods are attached to that class.
QUESTION
I need help to understand my code theoretically. Here is my lisp program:
...ANSWER
Answered 2021-Jun-07 at 21:26Here is your code, slightly reformatted:
QUESTION
I am trying to learn Common Lisp with the book Common Lisp: A gentle introduction to Symbolic Computation. In addition, I am using SBCL, Emacs, and Slime.
By the end of chapter 10, on the advanced section there is this question:
10.9. Write a destructive function CHOP that shortens any non-NIL list to a list of one element. (CHOP '(FEE FIE FOE FUM)) should return (FEE).
This is the answer-sheet solution:
...ANSWER
Answered 2021-Jun-07 at 16:15The point is about how parameters to functions are passed in Common Lisp. They are passed by value. This means that, when a function is called, all arguments are evaluated, and their values are assigned to new, local variables, the parameters of the function. So, consider your function:
QUESTION
I am trying to learn Common Lisp with the book Common Lisp: A gentle introduction to Symbolic Computation. In addition, I am using SBCL, Emacs, and Slime.
By the end of chapter 10, the author discuss the useful break function. In order to provide a background context, he presents this problematic function:
...ANSWER
Answered 2021-Jun-06 at 17:54If you navigate to the top frame in the debugger and press enter on that frame, you will see that commission
is not known to the debugger as a local variable:
QUESTION
I'm trying to figure out how to parse S-expressions in C on my own, in order to store data and code for my own rudimentary Lisp (written as a learning exercise, not for production).
Before explaining my code and my reasoning, I should explain that all I know about S-expressions is the introductory section of the Wikipedia article on it, and the occasional glance at Common Lisp code, so the naming of my structs and variables may be a bit off.
My language of implementation is C, and before I defined any functions I created the following structs:
...ANSWER
Answered 2021-Jun-06 at 15:05Don't use void*
. Use a union
. That's what union
s are for.
In this example, I use an "anonymous union", which means that I can just refer to its fields as though they were directly inside the Atom struct. (I changed the spelling of names according to my prejudices, so that types are Capitalised and constants are ALLCAPS. I also separated the typedef and struct declarations for Atom, in case Atom turns out to be self-referential.
QUESTION
I'm running into an odd issue with Common Lisp's format
directive that only shows itself in GNU CLISP, which leads me to wonder if it's a bug in the implementation.
Consider the following code
...ANSWER
Answered 2021-Jun-05 at 13:28This is a feature of GNU CLISP. See the documentation of *pprint-first-newline*
.
If you want a different output than that, bind either *print-pretty*
or *pprint-first-newline*
to nil during your format
invocation.
QUESTION
I am trying to learn Common Lisp with the book Common Lisp: A gentle introduction to Symbolic Computation. In addition, I am using SBCL, Emacs, and Slime.
By the end of chapter 9, the author shows the dribble tool. He shows the following:
I tried to reproduce the commands presented by the author. Considering the inputs, the only difference was the fact that I put a different location to save the file. In my environment, I did:
...ANSWER
Answered 2021-Jun-05 at 06:44Yes, by default, within Slime I don't think this works.
It will work within the SBCL Repl:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lisp
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page