lisp

Counting elements of a list and sublists

旧巷老猫 提交于 2019-12-18 09:29:16
问题 I'm trying to create a function to count all the elements in a list, including the elements of its sublists. initially, to get started, i came up with a basic function myList : (define myLength (lambda (L) (cond ((null? L) 0) (else (+ 1 (myLength (cdr L))))))) However, it doesn't help me account for function calls like: (numAtoms '()) "...should be 0" (numAtoms '(())) "...should be 0" (numAtoms '(1 1)) "...should be 2" (numAtoms '(1 (1 1) 1)) "...should be 4" (numAtoms '(1 (1 (1 1)) 1)) "..

How is set! defined in scheme?

Deadly 提交于 2019-12-18 07:24:29
问题 How would you implement your own set! function in Scheme? A set! function is a destructive procedure that changes a value that is defined taking into account the previous value. 回答1: As noted in the comments, set! is a primitive in Scheme that must be provided by the implementation. Similarly, you can't implement the assignment operator, = , in most programming languages. In Common Lisp, setf can be extended (using setf -expanders) to allow (setf form value) to work on new kinds of forms.

F# equivalent to Eval

心已入冬 提交于 2019-12-18 04:38:15
问题 Is there an F# equivalent to eval? My intent is to have my app load a small code sample from a file and essentially let file = "c:\mysample" let sample = loadFromFile file let results = eval(sample) I am new to F# and trying to figure out some of the limitations before I apply it to a project. Thank you 回答1: There is no function that would allow you to do this directly. However, when you want to compile an F# source file programatically, you can invoke the F# compiler from your application.

running scheme from emacs

假装没事ソ 提交于 2019-12-18 03:21:10
问题 I'm a newbie to LISP. I am attempting to invoke the scheme interpreter from within emacs (version 23 running on windows). I loaded the xscheme library by telling emacs to M-x load-library and then entering xscheme at the prompt in the minibuffer. The library loaded, and then I issued the M-x run-scheme command. (I realize that all this loading can be done from .emacs at startup, but I am not concerned with that at the moment.) So far so good - the *scheme* buffer has been created, and now I'm

What is a Lisp image?

梦想与她 提交于 2019-12-17 23:16:02
问题 Essentially, I would like to know what a Lisp image is? Is it a slice of memory containing the Lisp interpreter and one or more programs or what? 回答1: The Lisp image as dumped memory The image is usually a file. It is a dump of the memory of a Lisp system. It contains all functions (often compiled to machine code), variable values, symbols, etc. of the Lisp system. It is a snapshot of a running Lisp. To create an image, one starts the Lisp, uses it for a while and then one dumps an image (the

How to force Emacs not to display buffer in a specific window?

佐手、 提交于 2019-12-17 21:52:01
问题 My windows configuration looks like this: +----------+-----------+ | | | | | | | | | | | | | | | | +-----------+ | | | +----------+-----------+ And I use the lower right window for special displays (like help, completion etc.), but emacs insists on using that window when I call commands ( find-file-other-window , etc.) that use display-buffer , and resize that window as well. It's annoying... Is there a way that I can force emacs NOT to use that windows? I was thinking of advising display

What can you do with Lisp macros that you can't do with first-class functions?

江枫思渺然 提交于 2019-12-17 21:49:52
问题 I think I understand Lisp macros and their role in the compilation phase. But in Python, you can pass a function into another function def f(filename, g): try: fh = open(filename, "rb") g(fh) finally: close(fh) So, we get lazy evaluation here. What can I do with macros and not with functions as first class objects? 回答1: First of all Lisp has first-class functions too, so you could as well ask: "Why do I need macros in Lisp if I already have first-class functions". The answer to that is that

Why is the Lisp community so fragmented? [closed]

不羁岁月 提交于 2019-12-17 21:43:15
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . To begin, not only are there two main dialects of the language (Common Lisp and Scheme), but each of the dialects has many individual

Nicer pythonic `join` in common-lisp

情到浓时终转凉″ 提交于 2019-12-17 21:32:55
问题 In Edi Weitz's cl cookbook, for the pythonic join , this function is suggested: (defun join (separator list) (with-output-to-string (out) (loop for (element . more) on list do (princ element out) when more do (princ separator out)))) However, somehow I was thinking, there must be a way to express join in another way, maybe using format 's capabilities ... In Seibel's book, (in the chapter about format ) we find joining of strings in a list to a single string with the separator ", " by:

Reading a character without requiring the Enter button pressed

可紊 提交于 2019-12-17 20:57:31
问题 read-line and read-char both require you press Enter key after typing something. Is there any mechanism in Common Lisp that would allow the program to continue upon the press of any single character immediately, without requiring the additional step of pressing Enter? I'm trying to build a quick, dynamic text input interface for a program so users can quickly navigate around and do different things by pressing numbers or letters corresponding to onscreen menus. All the extra presses of the