cl-cookbook | The Common Lisp Cookbook | Learning library
kandi X-RAY | cl-cookbook Summary
kandi X-RAY | cl-cookbook Summary
The Common Lisp Cookbook
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Toggle the TOC
- set ready event listeners
- loops through an array and returns the first argument
- function to filter input
- Helper function to check if a form is disabled
- Loops through a b
- Calculate rta
- Formats a number
- function iterates over a and iterate over
- function used to filter inputs
cl-cookbook Key Features
cl-cookbook Examples and Code Snippets
Community Discussions
Trending Discussions on cl-cookbook
QUESTION
Windows 10, CLISP 2.49, FFI.
I have used the built-in FFI to start a windows loop and a basic windproc callback. The initial windows message WM_PAINT
is fine. In some tests, SetWindowPos
or minimizing/maximizing the window, all of which call WM_PAINT
, are also fine.
But when I, the user, grab the window edge to resize the window, it crashes. There is no lisp error. I've attempted to attach to CLISP via Visual Studio, but there is no windows exception either.
I've added (room)
and (ext:gc)
to check memory issues. I'm very suspicious that room
reports "Bytes available until next GC: 6,510"
being pretty low just before the program crashes. Multiple WM_PAINT
calls will succeed, but if "bytes available" is low, there's a good (but not 100%) chance of a crash.
ANSWER
Answered 2020-Nov-07 at 20:38Are the WM_PAINT
messages sent by Windows in the same thread that executes the main message loop?
- If yes, then it's likely a bug in CLISP. If you can reproduce it also with the current prerelease 2.49.92 (available from https://alpha.gnu.org/gnu/clisp/), it's worth submitting a bug report at https://gitlab.com/gnu-clisp/clisp/-/issues .
- If no, then there's currently no way to make this work with CLISP; I'd then recommend SBCL instead. The reason is that multithreading in CLISP is not ready for prime-time, while SBCL supports multiple threads well.
QUESTION
I'm sorry, this is a very newbie Common Lisp question.
I'm learning common-lisp and package system.
I started with "The Complete Idiot's Guide to Common Lisp Packages" from http://cl-cookbook.sourceforge.net/packages.html
In Chapter 1, the author defined a function foo
in the package :bob
ANSWER
Answered 2020-Aug-18 at 20:04You need to tell Lisp which package to use. In standard Common Lisp it is unspecified which packages to use. SBCL uses none. If you want symbols of the package CL to be available, you have to explicitly use that package.
Package JANE
QUESTION
I'm learning common-lisp and CLOS.
I started with the tutorial from http://cl-cookbook.sourceforge.net/clos-tutorial/
In Section 4.3, it mentioned that
A generic function is a lisp function which is associated with a set of methods and dispatches them when it's invoked.
It also present two functions generic-function-methods
and method-generic-function
:
ANSWER
Answered 2020-Aug-14 at 15:45Method-generic-function
gives you the generic function that the given method is associated with.Method-generic-function
is not imported into thecl-user
package in SBCL. You will find it insb-mop
(so,sb-mop:method-generic-function
). The MOP is not entirely incorporated in the Common Lisp standard.- For portable use of the entire MOP, use the library “Closer to MOP” (
closer-mop
). - In the REPL,
*
refers to the first return value of the last evaluated expression. In your case, that was the list of methods returned bygeneric-function-methods
. So you see that these two are more or less inverse functions in this one-to-many relation.
QUESTION
I am trying to understand the basics of the series
library and am studying the examples in the CL Cookbook
But if I try to evaluate one of this examples
...ANSWER
Answered 2020-Apr-19 at 11:48Reader macros for libraries typically need to be enabled explicitly.
According to the RELEASE-NOTES:
You can use SERIES::INSTALL for "use-package"ing Series in a way that extended special forms are shadow-import'ed and reader macros are installed.
I'm not sure why that is not exported.
I have not yet found a named-readtables
definition for series, but I'd guess that someone has done that alredy.
QUESTION
I'm a beginner in lisp and I'm unable to find out how to correctly use defpackage to load qtools (on arch linux). For simplicity if I run this example project in sbcl with loaded quicklisp https://github.com/Shinmera/qtools/tree/master/examples/helloworld this error appears
...ANSWER
Answered 2020-Apr-10 at 11:15You need to install the qtools
system.
- A system is a way to organize software libraries
- A package is a namespace
The two are theoretically unrelated. But often, when you load a system X, it defines a package named X.
In some cases (like qtools) there are many packages for one system, for example because the system wants to define different levels of API.
Another way to define multiple packages when loading one system comes from the fact that ASDF version 3.1 supports an extension copied from other build systems named package-inferred-systems, where each source file is implicitly mapped to one system and one package.
Here is a snippet of what Quicklisp shows when installing qtools
:
QUESTION
I'm having a problem acessing slots out of slot definitions. I can inspect class objects, see their slots definitions and even get some standard info about the slots definitions. However I can't access user-defined information about the slot definition.
I've already googled this for quite a while and ended up reading CLOS & MOP specifications, a bit of the Lisp Cookbook, about some MOP concepts, and some related questions on StackOverflow that didn't help much. I even readed a piece of SBCL's implementations, but to no avail.
From the pieces that I was able to put together, I can access many slots of a SLOT DEFINITION
via some functions, e.g. access the NAME
slot of the SLOT DEFINITION
using CLOSER-MOP:SLOT-DEFINITION-NAME
(which is certainly helpful), but I can't do so for slots that don't have one of these functions. For example, I can't access the REFERENCES
slot which is provided by the MITO
package when defining slots in a DEFCLASS
.
Here's a minimal working example:
...ANSWER
Answered 2019-Feb-14 at 21:08Slot names are symbols, so the package matters when using SLOT-VALUE
/ WITH-SLOTS
. In this case the references slots appears to be named by an internal symbol in the package MITO.CLASS.COLUMN
.
The inspector doesn't show the package name (because it's rarely needed), but you can see that the slot definition is of type MITO.DAO.COLUMN:DAO-TABLE-COLUMN-CLASS
, so you can use CLOSER-MOP:CLASS-SLOTS
to find the slot definition:
QUESTION
I've found this example from the Common Lisp Cookbook which shows how to start a TCP server with usocket.
The example creates a socket object and establishes a connection, and then writes to the socket. In case of error, the socket write is wrapped in an unwind-protect which will close the socket so it can be reused. I've rewritten the example to cause the error, but when I run this multiple times, I get a USOCKET:ADDRESS-IN-USE-ERROR
. The behavior is the same if I remove the socket-close
function calls.
ANSWER
Answered 2020-Mar-22 at 11:16The reason you get this is because of the nature of the TCP protocol: the connection is in a state called TIME-WAIT in the TCP state machine described by RFC793. A diagram of the state machine is on page 23 of RFC793.
The interesting bit of the state machine is when one end (who I'll call 'you') wants to close the connection – this is known as an 'active close', and in this case it's what you are initiating by the socket-close
calls. I'll call the other end 'them'. The normal sequence of events for an active close is:
- you send them a FIN packet;
- they ACK your FIN and send in turn a FIN;
- you ACK their FIN.
Now it's important to remember that any of these packets (their ACK and FIN are the same packet usually and I think always) can get lost, and the state machine needs to recover from this.
There's one particularly interesting packet which is the last ACK: it's particularly interesting because it's the last packet ever sent, which means that you have no way of knowing whether it reached them.
So consider the situation from both ends
From their end: they've sent a FIN and are waiting for your ACK for it. Now:
- either the ACK arrives in due course, in which case they know everything is wound up and they can dismantle everything involved in the connection.
- or, after waiting for the prescribed time, the ACK doesn't arrive, so they must assume that either their FIN was lost or your ACK to their FIN was lost, and so they must resend the FIN and go back to waiting for the ACK.
From your end: you've got their FIN and have sent the last ACK. But you have no idea whether that ACK ever got to them. So you wait for a prescribed time in order to give them a chance to realise that the ACK did not get their and resend their FIN. During this wait you can't dismantle the connection, because at any point you may get another FIN.
This waiting state is known as TIME-WAIT, and during it the endpoint of the connection can't be reused. And this is the problem you are seeing.
You need to sit in TIME-WAIT for twice the maximum segment lifetime (MSL): the MSL is how long a packet can be expected to sit in the network.
There are other waiting-states which can occur prior to TIME-WAIT of course, if earlier packets get lost. But TIME-WAIT is the only one which always occurs.
TIME-WAIT is often called TIME_WAIT due to languages which can't handle hyphens in names.
QUESTION
I need to do computations using multi-threading. I use SBCL and portability is not a concern. I am aware that bordeaux-threads
and lparallel
exist but I want to implement something at the relatively low level provided by the specific SBCL threading implementation. I need maximal speed, even at the expense of readability/programming effort.
We can define a sufficiently computation-intensive function that will benefit from multi-threading.
...ANSWER
Answered 2018-Aug-20 at 23:28The
splice-arglist
helpers are not needed at all (so I'll also skip details in them). Useapply
in your thread function instead:
QUESTION
I have a C# project in which I retreive grey-scale images from cameras and do some computation with the image data. The computations are quite time-consuming since I need to loop over the total image several times and I am doing it all on the CPU.
Now I would like to try to get the evaluation running on the GPU, but I have a lot of struggle achieving that, since I never did any GPU calculations before.
The software should be able to run on several computers with varying hardware, so CUDA for example is not a solution for me, since the code should also run on laptops which only have onboard graphics. After some research I came accross Cloo (found it on this project), which seems to be a quite resonable choice.
So far I integrated Cloo in my project and tried to get this hello world example running. I guess it is running, since I don´t get any exception, but I don´t know where I can see the printed output.
For my computations I need to pass the image to the GPU and I also need the x-y coordinates during the computation. So, in C# the computation looks like this:
...ANSWER
Answered 2018-Mar-07 at 13:15Let's reverse engineer the problem. Understanding the efficient processing of the "dependency-chain" of image[][], image_height, image_width, a, b
for
-loops has a poor performance
given the defined code, there could be just a single loop, thus with reduced overhead costs and best with also maximising cache-aligned vectorised code.
Cache-Naive re-formulation:
QUESTION
How do we get file attributes ? I primarily am looking to get the size, but also its last access time and other attributes.
I only found (file-length some-file)
that gets a stream so is used this way:
ANSWER
Answered 2017-Oct-20 at 14:42With Osicat, you call stat
on the file and you get a bunch of things in a structure:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cl-cookbook
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