implementations of lisp functions
Asked Answered
D

2

0

In C, if I want to see a function that how to work, I open the library which provides the function and analyze the code. How can be implementations of the lisp functions seen? For example, intersection function

Dusen answered 15/10, 2015 at 6:22 Comment(5)
In C, you can only do that if the library is free software. For a proprietary library, you are stuck.... And on Linux, for system calls, most of the job is done inside the kernel, so it is much harder than what you believeLamoureux
wow I didn't know it. thanks @BasileStarynkevitchDusen
This is a very low quality question. The question is a poor fit for Stackoverflow (it is not about an actual programming problem) and the author has shown no effort.Alexandrina
@itsnotmyrealname: it's not about me. It's about you. You should at least have described which functions's source code in what implementation on what operating system you have tried to find and what you tried. Lisp is a group of languages. Finding source code of the actual language implementation might be different.Alexandrina
intersection implemented with equal I try to solve the problem #33126389 @Rainer JoswigDusen
W
2

You can also look at the source code of lisp functions.

For example, the source files for CLISP, one Common Lisp implementation, are available here: http://www.clisp.org/impnotes/src-files.html

If you want to examine the implementation of functions related to lists, you can look at the file: http://clisp.cvs.sourceforge.net/viewvc/clisp/clisp/src/list.d

Whoredom answered 15/10, 2015 at 6:33 Comment(0)
A
1

The usual answer is "M-."

Assuming you have a properly configured IDE, and the source code of the function, clicking on its name and pressing M-. (that's Meta, or Alt or Option or Escape, and dot/period; or whatever key your IDE uses) should reveal its definition (or, for a generic function, definitions, plural; including any compiler macros that might optimize out some cases). Sometimes it's on a right-click or other mouse menu or toolbar.

If the source isn't available, you can often see the actual compiled form by evaluating (disassemble 'function)

Most IDE's, including perennial favourite Emacs+Slime, have other Inspection operations on the menu as well.

In a non-IDE environment, most compilers have reflection tools of their own (compiler-dependant) which are usually also mapped by the Swank library that Slime uses; one might find useful function in that package.

And this really should be documented in your IDE's manual.


I should postscript this that:

You really shouldn't care about the implementation of the core library functions; their contractual behavior is very well documented in the CLHS standard, which is available online and eg, Quicklisp has an utility to link it to Slime (C-c C-d h on a symbol in the COMMON-LISP package); for all well-written Lisp libraries, there should be documentation attached to functions, variables, classes, etc. accessible via the documentation function in the REPL or the IDE's menus and Inspection windows.

Core library functions are often highly optimized and far more complex than most user-level code should want to be, and often call down into compiler-specific "guts" that one should avoid doing in application code.

Accept answered 15/10, 2015 at 16:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.