[
Programming In Lisp With CuspSergey KolosVer 0.0.3 Installation
Getting Started: Your First Lisp ProgramCreate Lisp Project
Writing Code and Basic NavigationOpen file main.lisp and after (in-package :new-lisp1) write the following code:(defun f () "hello, world!") ![]() Save the file. As file is saved it is immidiately compiled. You can check this by typing in lower part of REPL (new-lisp1::f) and hitting Enter key or pressing Send button: ![]() The result is displayed in upper part of REPL: ![]() To export the function f from the package new-lisp1 do the following (these operations are overkill for such a short source code, but they show important navigation features of Cusp IDE):
![]()
![]()
![]()
![]()
![]() Quitting And Starting AgainOnce you tired of coding and wish to launch "Unreal Tournament" you will want to close Eclipse. Go ahead and just close it, you don‘t need to do anything special to your Lisp session. To get back to your code you open Eclipse, then make sure that you are in Lisp Perspective, if not select it. Before you can continue coding your program, you need to load it. To do this, right click on .asd file in your project and select Load asd : ![]() This will compile and load all files for your package. You can check this by running new-lisp1:f Dealing With ProblemsDebuggingIf something goes wrong in your code, you get into debugger. For example, enter g in REPL:![]() Hitting send, opens debugger: ![]() The debugger has three regions:
InspectorSome regions of upper part of REPL are hyperlinks. These are objects that can be inspected. To inspect you just click on a hyperlink. For example, enter *package* in REPL:![]() and follow #<PACKAGE "COMMON-LISP-USER"> hyperlink. You‘ll get into Inspector: ![]() which prints details of the object #<PACKAGE "COMMON-LISP-USER">. Compilation Warnings and ErrorsAdd to main.lisp following code:(defun h() "Call function that is not defined" (hh))When you save the file, Cusp tries to send it for compilation. In this case saving generates item in Problems list: ![]() It is generated because we tried to compile main.lisp before we loaded package new-lisp1.asd. See section "Quitting And Starting Again". Now, if you load new-lisp1.asd compilation produces a warning, which is added to Problems tab and put on bar left to the code: ![]() Getting HelpHyperSpec and LispDocHyperSpecThe main Lisp reference is HyperSpec. To find description of a symbol in HyperSpec put a cursor at the symbol and hit Alt+H (or select HyperSpec in Lisp menu): ![]() This will open a browser window in Eclipse with page describing the symbol: ![]() LispDoc The other good source of documentation is LispDoc. On its website it is described as "a search engine for documentation of the Common Lisp programming language and many of its libraries". When you request LispDoc search on a symbol with Alt+L (or LispDoc from Lisp menu) you get a page in a browser with example code of this symbol and a bunch of links to Lisp documents, books or manuals that mention this symbol: ![]() AutoHelpThe environment supports automatic display of help information. It can sugest completions of symbols and show call signature and documentation string. The examples below show how this feature works ( Notice how functions defined in our code also display this information ):![]() ![]() Cusp also support fuzzy way for proposing autocompletion, but it has to be turned on in preferences. To do this, open Windows->Preferences... menu, and set corresponding options: ![]() Then typing m-v-b will suggest multiple-value-bind: ![]() AproposYou can also search internal documentation using Apropos. For non-Unix types, Appropos gives a brief one-line summary for a given command.![]() Big ProjectsAdvanced Navigation FeaturesThere are several features in Cusp that help in working with big Lisp projects.
![]()
![]()
Adding Files to the ProjectTo add another file to the project you have two options:
![]() This opens dialog box, where you can select name of new file. Hitting Finish will create new file.
- add code (:file "file-name" :depends-on ("defpackage")) to :components clause of .asd file: ![]() Using LibrariesLoading Installed LibraryFirst we will see how to use library that is already installed. The patch cusp-patch0.8.49.zip contains Lisp regex library cl-ppcre.You can load cl-ppcre library by clicking on "Load installed package" button: ![]() This open "Load package" dialog: ![]() In this dialog box select cl-ppcre and click OK. The library will be compiled and loaded, as can be seen in "Change package" dialog box: ![]() To check that the library is loaded run the following in REPL: (cl-ppcre:scan "(a)*b" "xaaabd") : ![]() Installing New LibraryInstalling new library is as simple as extracting its contents to sbcl/site-systems folder. We‘ll try installing split-sequence library. First go to cliki webpage of this library: http://www./SPLIT-SEQUENCE. At the end of this page there is a link where you can get this library from: http://ww./cclan/split-sequence.tar.gz. Download it and extract to sbcl/site-systems folder:![]() This is all to make library available for loading throug "Load installed package". After the library is loaded, we can run split-sequence function: ![]() It is also possible to install library into a custome folder, not just sbcl/site-systems. For this you need to add root folder to libraries in preferences. To do this go to Windows->Preferences... menu, and select Lisp->Implementations page: ![]() With such settings it is now possible to extract split-sequence.tar.gz to any subfolder of c:/temp/system folder for library to be immidiately visible to lisp. Using External Library in Your PackageOnce a library is installed you can use functions it exports in your code. To do this you need to perform three steps:
![]()
![]()
![]() Now we can test the new function by running (new-lisp1::split-path "usr/bin"): ![]() When you next time start new lisp session you no longer need to load split-sequence library - it will be loaded automatically when you choose Load asd in context menu of new-lisp1.asd file. What‘s NextTODO: Add links here.[ScratchPad] parent nodes: LispWithCusp Scratch Pad[WikiSettings] parent nodes: LispWithCusp Wiki SettingsThese are your default global settings. [global.importance.low.color: grey] [global.importance.high.bold: true] [global.contact.icon: contact] [global.todo.bold: true] [global.todo.icon: pin] [global.wrap: 70] [icon: cog] |
|
来自: ShangShujie > 《pptr……》