lisp

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

Generating powerset in one function, no explicit recursion, and using only simplest primitives in Racket

北城余情 提交于 2021-01-04 02:10:01
问题 Note: this is a bonus for homework, but I have spent way too long on trying things to no avail. Help is much appreciated, but not necessary I suppose. Premise: generate a powerset for a list of numbers, but without using any helpers, explicit recursion, looping, or functions/constants other than cons , first , rest , empty? , empty , else , lambda , and cond , while using only one define on the language level Intermediate Student with Lambda . The order of the powerset does not matter. What I

Generating powerset in one function, no explicit recursion, and using only simplest primitives in Racket

微笑、不失礼 提交于 2021-01-04 01:58:54
问题 Note: this is a bonus for homework, but I have spent way too long on trying things to no avail. Help is much appreciated, but not necessary I suppose. Premise: generate a powerset for a list of numbers, but without using any helpers, explicit recursion, looping, or functions/constants other than cons , first , rest , empty? , empty , else , lambda , and cond , while using only one define on the language level Intermediate Student with Lambda . The order of the powerset does not matter. What I

How do foldl and foldr work, broken down in an example?

房东的猫 提交于 2020-12-30 08:44:34
问题 Okay, I am new with scheme/racket/lisp. I am practicing creating my own functions, syntax, and recursion, so I want to make my own foldl and foldr functions that do exactly what the predefined versions do. I can't do it because I just don't understand how these functions work. I have seen similar questions on here but I still don't get it. Some examples broken down would help! Here is my (incorrect) process: (foldl - 0 '(1 2 3 4)) I do 0 -(4-3-2-1) and get 2 which is the right answer (foldl -

How do foldl and foldr work, broken down in an example?

谁都会走 提交于 2020-12-30 08:44:12
问题 Okay, I am new with scheme/racket/lisp. I am practicing creating my own functions, syntax, and recursion, so I want to make my own foldl and foldr functions that do exactly what the predefined versions do. I can't do it because I just don't understand how these functions work. I have seen similar questions on here but I still don't get it. Some examples broken down would help! Here is my (incorrect) process: (foldl - 0 '(1 2 3 4)) I do 0 -(4-3-2-1) and get 2 which is the right answer (foldl -

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 .