lisp

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

Does Scheme/Racket have an enumeration operation?

痴心易碎 提交于 2019-12-05 08:50:03
Does Scheme/Racket have an enumeration notation equivalent to the [a..b] notation in Haskell? In Haskell, [1..5] evaluates to a list [1,2,3,4,5]. (for/list ([i (in-range 1 6)]) i) (sequence->list (in-range 1 6)) (require srfi/1) (iota 5 1) (for/list ([i 5]) (+ 1 i)) (build-list 5 add1) Also, (in-range 1 6) (which is a sequence ) by itself is useful in many contexts. 来源: https://stackoverflow.com/questions/7144248/does-scheme-racket-have-an-enumeration-operation

Common Lisp a Lisp-n?

自作多情 提交于 2019-12-05 08:46:20
I'm aware that Common Lisp has different binding environments for functions and variables, but I believe that it also has another binding environment for tagbody labels. Are there even more binding environments than this? If so, then is it fair to categorize Common Lisp as a Lisp-2? These question are not meant as pedantry or bike-shedding, I only want to gain a better understanding of Common Lisp and hopefully get some pointers into where to dig deeper into its spec. danlei I'm aware that Common Lisp has different binding environments for functions and variables, That would be namespaces ,

How can I tell if a list has a third item?

倖福魔咒の 提交于 2019-12-05 08:43:20
I have a function that takes a list that either has two or three elements. ;; expecting either ((a b c) d) or ((a b c) d e) (define (has-third-item ls) (if (null? (caddr ls)) false true) ) But this code fails with mcar: expects argument of type <mutable-pair>; given () on the (null? (caddr ls)) expression. I also tried (eq? '() (caddr ls)) but it didn't work either. How do I tell if there's a third item or not? You don't want caddr, you want (if (null? (cddr ls)) ... Or just use length to find the length of the list, and compare it to the value you're interested in. The '() that terminates a

Racket: Identifying tail recursion?

浪尽此生 提交于 2019-12-05 08:32:39
I wrote two different functions in racket to determine whether a list of numbers is ascending: (define (ascending list) (if (<= (length list) 1) #t (and (< (car list) (car (cdr list))) (ascending (cdr list))))) (define (ascending-tail list) (ascending-tail-helper #t list)) (define (ascending-tail-helper prevBool rest) (if (<= (length rest) 1) prevBool (ascending-tail-helper (and prevBool (< (car rest) (car (cdr rest)))) (cdr rest)))) I had the hardest time determining whether or not the first ascending was tail recursive, so I rewrote it using what I believe to be tail recursion. The reason

How do I manage common lisp dependencies?

≡放荡痞女 提交于 2019-12-05 08:19:54
What's the lisp equivalent of a pip requirement file, ruby gemfile, node package.json, etc? I'm not entirely sure how asdf and quicklisp relate if those are the proper things to use. A .asd file is a requirements file. Use quicklisp to install requirements. Use ASDF to define a "system". Create a my-system.asd file. (asdf:defsystem #:my-system :serial t :description "Describe my-system here" :author "My Name <my.name@example.com>" :license "Specify license here" :depends-on (#:hunchentoot #:cl-who) :components ((:file "package") (:file "dispatch"))) This creates the system named #:my-system. I

How can I define the address that swank server should listen to?

≡放荡痞女 提交于 2019-12-05 07:34:16
There is no argument for setting the address to bind to when starting swank server: * (describe 'swank:create-server) => ... Lambda-list: (&KEY (PORT DEFAULT-SERVER-PORT) (STYLE *COMMUNICATION-STYLE*) (DONT-CLOSE *DONT-CLOSE*) (CODING-SYSTEM *CODING-SYSTEM*)) ... How can I do it? Bind swank::*loopback-interface* to a string containing the ip address for the swank server. It defaults to the localhost ("127.0.0.1"). For security, take care that the swank address is not wide open to the world as it would leave the computer vulnerable for intrusion. If the goal is to access swank from another

Lisp data security/validation

£可爱£侵袭症+ 提交于 2019-12-05 05:27:30
This is really just a conceptual question for me at this point. In Lisp, programs are data and data are programs. The REPL does exactly that - reads and then evaluates. So how does one go about getting input from the user in a secure way? Obviously it's possible - I mean viaweb - now Yahoo!Stores is pretty secure, so how is it done? The REPL stands for Read Eval Print Loop. (loop (print (eval (read)))) Above is only conceptual, the real REPL code is much more complicated (with error handling, debugging, ...). You can read all kinds of data in Lisp without evaluating it. Evaluation is a

Why were FEXPRs abandoned in Common Lisp? [closed]

北城余情 提交于 2019-12-05 05:14:06
Closed . This question needs details or clarity . It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post . Closed 6 years ago . Many LISPs had FEXPRs but they were not included in CL. I read that this was because FEXRPs don't work well with static analysis. Can someone explain this? From the Wikipedia article on FEXPRs : At the 1980 Conference on Lisp and Functional Programming, Kent Pitman presented a paper "Special Forms in Lisp" in which he discussed the advantages and disadvantages of macros and fexprs, and ultimately

Just getting used to paredit in emacs on OS X - how come C-) doesn't work?

喜你入骨 提交于 2019-12-05 04:55:31
I've recently set up a Common Lisp programming environment in Mac OS X Leopard. One emacs module which I've found to be indispensable is paredit. Paredit is doing its part to help me wrangle my Lisp code more easily, but I've ran into a bit of a snare. C-), bound to paredit-forward-slurp-sexp , is not forward slurping sexps but instead echoing the number 0 . I'm using a Mac, alternating between iTerm and Terminal. The same problem is present in both apps. I tried the same key combination in GNU Emacs' GUI version, and lo, it worked. Unfortunately the graphical version of Emacs does not satisfy