common-lisp

Arrays vs. lists in Lisp: Why are lists so much faster in the code below?

强颜欢笑 提交于 2021-01-27 05:49:46
问题 I got an unexpected result while solving Problem 75 in Project Euler. My code does find the correct solution, but it behaves strangely. My solution consists of traversing a Pythagorean tree (Barning's matrices) until the perimeter limit is reached, counting the numbers of times the perimeter assumed each value, and, lastly, counting the perimeter lengths that occurred only once. My admittedly untidy but functioning code is: (defparameter *barning-matrixes* '(#(1 -2 2) #(2 -1 2) #(2 -2 3) #(1

use of &rest and &key at the same time in Common Lisp

半世苍凉 提交于 2021-01-26 17:28:03
问题 I want to use both &rest and &key at the same time. However, the attempted code below: (defun test (&rest args &key (name "who")) nil) (test 1 2 3 4 5 :name "hoge") causes an error: *** - TEST: keyword arguments in (1 2 3 4 5 :NAME "hoge") should occur pairwise and when I gives only keyword parameter like (test :name "hoge") , it works. Is it possible to use both &rest and &key? 回答1: It's generally not a good idea to mix rest parameters with keyword parameters within a function definition in

use of &rest and &key at the same time in Common Lisp

浪子不回头ぞ 提交于 2021-01-26 17:22:54
问题 I want to use both &rest and &key at the same time. However, the attempted code below: (defun test (&rest args &key (name "who")) nil) (test 1 2 3 4 5 :name "hoge") causes an error: *** - TEST: keyword arguments in (1 2 3 4 5 :NAME "hoge") should occur pairwise and when I gives only keyword parameter like (test :name "hoge") , it works. Is it possible to use both &rest and &key? 回答1: It's generally not a good idea to mix rest parameters with keyword parameters within a function definition in

use of &rest and &key at the same time in Common Lisp

断了今生、忘了曾经 提交于 2021-01-26 17:22:21
问题 I want to use both &rest and &key at the same time. However, the attempted code below: (defun test (&rest args &key (name "who")) nil) (test 1 2 3 4 5 :name "hoge") causes an error: *** - TEST: keyword arguments in (1 2 3 4 5 :NAME "hoge") should occur pairwise and when I gives only keyword parameter like (test :name "hoge") , it works. Is it possible to use both &rest and &key? 回答1: It's generally not a good idea to mix rest parameters with keyword parameters within a function definition in

use of &rest and &key at the same time in Common Lisp

与世无争的帅哥 提交于 2021-01-26 17:18:42
问题 I want to use both &rest and &key at the same time. However, the attempted code below: (defun test (&rest args &key (name "who")) nil) (test 1 2 3 4 5 :name "hoge") causes an error: *** - TEST: keyword arguments in (1 2 3 4 5 :NAME "hoge") should occur pairwise and when I gives only keyword parameter like (test :name "hoge") , it works. Is it possible to use both &rest and &key? 回答1: It's generally not a good idea to mix rest parameters with keyword parameters within a function definition in

Nested Loops Using Loop Macro in Common Lisp

点点圈 提交于 2020-12-26 09:38:44
问题 I am trying to implement a basic nested loop in CL, but the Loop macro is resisting this. Basically, I would like to find all possible products of 3-digit numbers and accumulate them into a list. Here is my attempt: (loop for x downfrom 999 to 998 do (loop for y downfrom 999 to 998 collect (* x y))) The code above returns NIL for some reason. By the way, I realize that I only run down to 998, but this is done for testing purposes. What could I do to obtain a list like this: (999*999 999*998 .

Nested Loops Using Loop Macro in Common Lisp

我是研究僧i 提交于 2020-12-26 09:38:23
问题 I am trying to implement a basic nested loop in CL, but the Loop macro is resisting this. Basically, I would like to find all possible products of 3-digit numbers and accumulate them into a list. Here is my attempt: (loop for x downfrom 999 to 998 do (loop for y downfrom 999 to 998 collect (* x y))) The code above returns NIL for some reason. By the way, I realize that I only run down to 998, but this is done for testing purposes. What could I do to obtain a list like this: (999*999 999*998 .

Why does `sxhash` return a constant for all structs?

情到浓时终转凉″ 提交于 2020-12-05 03:42:32
问题 When using the Common Lisp sxhash function on structs I'm getting the same value for all structs (in SBCL only structs of the same type). For instance, the following code prints two lists of integers all of which have the same value. (progn (defstruct foo data) (print (mapcar #'sxhash (loop for i below 10 collect (make-foo :data i)))) (defstruct bar data) (print (mapcar #'sxhash (loop for i below 10 collect (make-bar :data i))))) ;;; Allegro (319 319 319 319 319 319 319 319 319 319) (319 319

Why does `sxhash` return a constant for all structs?

柔情痞子 提交于 2020-12-05 03:40:50
问题 When using the Common Lisp sxhash function on structs I'm getting the same value for all structs (in SBCL only structs of the same type). For instance, the following code prints two lists of integers all of which have the same value. (progn (defstruct foo data) (print (mapcar #'sxhash (loop for i below 10 collect (make-foo :data i)))) (defstruct bar data) (print (mapcar #'sxhash (loop for i below 10 collect (make-bar :data i))))) ;;; Allegro (319 319 319 319 319 319 319 319 319 319) (319 319