lisp

How can I convert a string into exact number in Scheme Lisp?

那年仲夏 提交于 2019-12-08 06:44:48
问题 For example, I have this string: "6119726089.12814713" If I do (string->number "6119726089.12814713") - using the SISC implementation the result is 6.119726089128147e9 - and in Guile implementation is 6119726089.128147 but I would like an exact number, like: 611972608912814713/100000000 without loss precision. I'd like a function like (string->exact) or something like this. NOTE: please fix my non-native English and remove this message. Thanks. 回答1: Use (string->number "#e6119726089.12814713"

Passing a list of functions as an argument in common Lisp

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 06:13:19
问题 Say there is a function F. I want to pass a list of functions as an argument into function F. Function F would go through each function in the list one by one and apply each one to two integers: x and y respectively. For example, if the list = (plus, minus, plus, divide, times, plus) and x = 6 and y = 2 , the output would look like this: 8 4 8 3 12 8 How do I implement this in common Lisp? 回答1: There are many possibilities. CL-USER> (defun f (x y functions) (mapcar (lambda (function) (funcall

Building the built-in procedure “build-list” in Racket

旧巷老猫 提交于 2019-12-08 06:02:02
问题 I am trying to build the built-in procedure build-list in Racket. The built-in function works like this: (build-list 10 (lambda (x) (* x x))) >> '(0 1 4 9 16 25 36 49 64 81) My implementation is a recursive definition for a recursive procedure: (define (my-build-list-recur list-len proc) (if (= list-len 0) '() (cons (proc (sub1 list-len)) (my-build-list-recur (sub1 list-len) proc)))) When I call my implementation, I have: (my-build-list-recur 10 (lambda (x) (* x x))) >> '(81 64 49 36 25 16 9

Help with installing ECL (Embeddable Common Lisp) via mingw32 or mingw-64 on Win7-64

醉酒当歌 提交于 2019-12-08 04:55:17
问题 I'm trying to compile ECL 10.4.1 on my Win7 64-bit box, but am having issues. I've attempted the build with both mingw32/MSYS and mingw-w64/MSYS, using the exact packages linked to here. Both have failed. With mingw32: ./configure passes, make fails as follows: gcc -DECLDIR="\"/usr/local/lib/ecl-10.4.1\"" -I. -Ic:/my_home/ecl-10.4.1/build -I/c/my_home/ecl-10.4.1/src/c -I../ecl/gc -DECL_API -DECL_NO_LEGACY -g -O2 -Dmingw32 -c -o main.o tmp.c In file included from c:/my_home/ecl-10.4.1/src/c

How to access object decoded from JSON by cl-json?

时光毁灭记忆、已成空白 提交于 2019-12-08 02:52:08
问题 I am trying to get JSON import in Common Lisp. I figured out how to decode an object from a JSON string, but I don't know how to access the properties of the object that's returned. To decode a string (and store the result in ***tempjson**), I do this: (defun test-json () (with-input-from-string (s "{\"foo\": [1, 2, 3], \"bar\": true, \"baz\": \"!\"}") (defparameter *tempjson* (json:decode-json s)))) How can I access *tempjson* data. For example, how can I get the value of the foo property?

Eval and lexical variables

末鹿安然 提交于 2019-12-08 02:14:53
问题 I'm doing a small project just for fun, and I added eval support for it to make debug easier. But later I found a problem: (let ((x 1)) (eval (1+ x))) (defun foo (x form) (eval form)) (foo 1 '(1+ x)) Code above won't work. Could someone please explain why and how to work it around? Thanks very much. 回答1: First, though (let ((x 1)) (eval (1+ x))) may look like it does work (it certainly does something), it is likely not doing, what you intend it to do. eval is a regular function, so it

Getting all possible combinations of x booleans (Racket, Scheme)

耗尽温柔 提交于 2019-12-08 01:52:42
问题 i have a problem. How do I get all possible combinations of x booleans in Racket? (on a low language level) I need something like that: For x=1 (list (list false) (list true)) For x=2 (list (list false false) (list false true) (list true false) (list true true)) For x=3 (list (list false false false) (list false false true) (list false true false) (list false true true) (list true false false) (list true false true) (list true true false) (list true true true)) etc. I have no idea how to do

How do I get a terminal program to honour cursor keys?

懵懂的女人 提交于 2019-12-08 01:26:52
问题 I'm using ccl/openmcl on Mac OS X. (latest versions of both). When the lisp prompt is displayed, using the cursor keys to navigate the current line results in escape codes, rather than movement, eg: Welcome to Clozure Common Lisp Version 1.2-r9226-RC1 (DarwinX8664)! ? (^[[D Here I've pressed the ( key, and then the left cursor key. When I run ccl/openmcl on a Debian Etch box, the cursor behaves as expected, and moves the insert point one position left. I guess this is some sort of terminal

Function name and dynamic binding in Common Lisp

大兔子大兔子 提交于 2019-12-07 23:57:59
问题 I'm reading Peter Norvig's Paradigms of AI . In chapter 6.2, the author uses code like below ( not the original code, I picked out the troubling part ): Code Snippet: (progv '(op arg) '(1+ 1) (eval '(op arg))) As the author's original intent, this code should return 2 , but in sbcl 1.1.1 , the interpreter is apparently not looking up op in the environment, throwing out op: undefined function . Is this implementation specific? Since the code must have been tested on some other lisp. p.s

load external with emacs-slime

北城以北 提交于 2019-12-07 22:08:53
问题 I'd like to install slime on my Emacs 23.2.1. Since M-x slime doesn't succeed in start it, I modified the ~/.emacs file. (setq inferior-lisp-program "/usr/bin/sbcl") (add-to-list 'load-path "/usr/share/emacs/site-lisp/slime/") (require 'slime) (slime-setup) Of course this doesn't work for the slime path in the second line of ~/.emacs file should be /usr/share/common-lisp/source/swank instead. However, after I changed this directory, the error remains. It says like this: Couldn't load "/usr