land-of-lisp

Using 'ash' in LISP to perform a binary search?

别说谁变了你拦得住时间么 提交于 2019-12-10 06:25:29
问题 So, I'm reading Land of Lisp now, and Lisp is turning out to be quite different than other programming languages that I've seen. Anyways, the book provides some code that we're meant to enter into the CLISP REPL: (defparameter *small* 1) (defparameter *big* 100) (defun guess-my-number () (ash (+ *small* *big*) -1)) (defun smaller () (setf *big* (1- (guess-my-number))) (guess-my-number)) (defun bigger () (setf *small* (1+ (guess-my-number))) (guess-my-number)) Now, the basic goal is to create

Using 'ash' in LISP to perform a binary search?

送分小仙女□ 提交于 2019-12-05 08:52:39
So, I'm reading Land of Lisp now, and Lisp is turning out to be quite different than other programming languages that I've seen. Anyways, the book provides some code that we're meant to enter into the CLISP REPL: (defparameter *small* 1) (defparameter *big* 100) (defun guess-my-number () (ash (+ *small* *big*) -1)) (defun smaller () (setf *big* (1- (guess-my-number))) (guess-my-number)) (defun bigger () (setf *small* (1+ (guess-my-number))) (guess-my-number)) Now, the basic goal is to create a number guessing game wherein the user/player chooses a number, and then the computer tries to guess

Stack overflow from recursive function call in Lisp

北战南征 提交于 2019-11-29 19:29:31
问题 I am learning Lisp from the book "The Land of Lisp" by Conrad Barski. Now I have hit my first stumbling block, where the author says: Calling yourself in this way is not only allowed in Lisp, but is often strongly encouraged after showing the following example function to count the items in a list: (defun my-length (list) (if list (1+ (my-length (cdr list))) 0)) When I call this function my-length with a list containing a million items, I get a stack overflow error. So either you never expect

Can you program without REPL on Lisp?

我与影子孤独终老i 提交于 2019-11-29 15:39:54
So I just got Land of Lisp and started to do the first program. I have a couple questions. Is there a way to just write some code and run it through a compiler, or interpreter, and not use the REPL thing? I don't like it much. I can't seem to go back if I messed up. It just kinda says "Ha you screwed up, retype that whole function." I would also like to know what the point of REPL is. Non-REPL work flow Edit your file Compile the file using compile-file ; fix errors and warnings; repeat. Load the file using load ; evaluate the form you want; repeat Example $ cat > f.lisp <<EOF (defun f (x) (if

Can you program without REPL on Lisp?

我的未来我决定 提交于 2019-11-27 19:35:03
问题 So I just got Land of Lisp and started to do the first program. I have a couple questions. Is there a way to just write some code and run it through a compiler, or interpreter, and not use the REPL thing? I don't like it much. I can't seem to go back if I messed up. It just kinda says "Ha you screwed up, retype that whole function." I would also like to know what the point of REPL is. 回答1: Non-REPL work flow Edit your file Compile the file using compile-file; fix errors and warnings; repeat.

Eliminating my explicit state passing via like, monads and stuff

人走茶凉 提交于 2019-11-27 02:47:49
问题 I'm working through the book Land of Lisp in F# (yeah weird, I know). For their first example text adventure, they make use of global variable mutation and I'd like to avoid it. My monad-fu is weak, so right now I'm doing ugly state passing like this: let pickUp player thing (objects: Map<Location, Thing list>) = let objs = objects.[player.Location] let attempt = objs |> List.partition (fun o -> o.Name = thing) match attempt with | [], _ -> "You cannot get that.", player, objs | thing :: _,