racket

Scheme Beginning Student, Function Body Extra Part

送分小仙女□ 提交于 2020-04-17 21:37:31
问题 I attempted to follow the solution provided in this question, but it simply didn't work. Essentially, my function works like so: (define (item-price size normal-addons premium-addons discount) (define price 0) (+ price (* normal-addon-cost normal-addons) (* premium-addon-cost premium-addons) size) (cond .. some conditions here [else price])) However, I am met with the following error: define: expected only one expression for the function body, but found 2 extra parts Now, I've tried wrapping

Stepping back in DrRacket stepper

谁都会走 提交于 2020-04-16 02:52:41
问题 Trying to debug using the stepper in Dr. Racket but as soon as the error pops up the stepper's buttons get turned off. Any way to step back after an error to better see where the bug is? 回答1: Stepper's author here: as soegaard says, this sounds like a bug, but it will be hard to fix without a sequence of steps to help reproduce. FWIW, basic stepping in and around runtime & syntax bugs is a part of the standard release checks. 来源: https://stackoverflow.com/questions/60962884/stepping-back-in

Encoding Huffman Tree Scheme [closed]

萝らか妹 提交于 2020-04-16 02:16:09
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 days ago . I am trying to write a function, (codeWords t) , which traverses a Huffman tree (adds #\0 when it goes left, adds #\1 when it goes right...) and returns these values in pairs of the symbol at a leaf along with its associated encoding as a string over the characters #\0 and #\1 . Similar to what this or

How can I transform this code into Racket/ Scheme

一个人想着一个人 提交于 2020-03-25 19:15:06
问题 This is the code I want translated into Racket: public static ArrayList<Integer> convert(int k, int n) { ArrayList<Integer> lst = new ArrayList<>(); while (k / n != 0) { lst.add(k % n); k = k/n; } lst.add(k % n); return lst; } e.g. in Racket the (convert 23 2) should return the binary of the decimal 23 , which is (list 1 0 1 1 1) . This is what I got so far: (define (convert k n) (cond [(> (/ k n) 0) (list(modulo k n))] [else 0] )) It works for the first element of the list. Thanks for any

6 件你应该用 Emacs 做的事

给你一囗甜甜゛ 提交于 2020-03-24 11:47:31
本文参考原文- http://bjbsair.com/2020-03-22/tech-info/2125/ 下面六件事情你可能都没有意识到可以在 Emacs 下完成。此外还有我们的新备忘单,拿去,充分利用 Emacs 的功能吧。-- Seth Kenlon(作者) 想象一下使用 Python 的 IDLE 界面来编辑文本。你可以将文件加载到内存中,编辑它们,并保存更改。但是你执行的每个操作都由 Python 函数定义。例如,调用 upper() 来让一个单词全部大写,调用 open 打开文件,等等。文本文档中的所有内容都是 Python 对象,可以进行相应的操作。从用户的角度来看,这与其他文本编辑器的体验一致。对于 Python 开发人员来说,这是一个丰富的 Python 环境,只需在配置文件中添加几个自定义函数就可以对其进行更改和开发。 这就是 Emacs 对 1958 年的编程语言 Lisp 所做的事情。在 Emacs 中,运行应用程序的 Lisp 引擎与输入文本之间无缝结合。对 Emacs 来说,一切都是 Lisp 数据,因此一切都可以通过编程进行分析和操作。 这造就了一个强大的用户界面(UI)。但是,如果你是 Emacs 的普通用户,你可能对它的能力知之甚少。下面是你可能没有意识到 Emacs 可以做的六件事。 使用 Tramp 模式进行云端编辑 Emacs

6 件你应该用 Emacs 做的事

那年仲夏 提交于 2020-03-21 01:37:15
3 月,跳不动了?>>> 下面六件事情你可能都没有意识到可以在 Emacs 下完成。此外还有我们的新备忘单,拿去,充分利用 Emacs 的功能吧。 想象一下使用 Python 的 IDLE 界面来编辑文本。你可以将文件加载到内存中,编辑它们,并保存更改。但是你执行的每个操作都由 Python 函数定义。例如,调用 upper() 来让一个单词全部大写,调用 open 打开文件,等等。文本文档中的所有内容都是 Python 对象,可以进行相应的操作。从用户的角度来看,这与其他文本编辑器的体验一致。对于 Python 开发人员来说,这是一个丰富的 Python 环境,只需在配置文件中添加几个自定义函数就可以对其进行更改和开发。 这就是 Emacs 对 1958 年的编程语言 Lisp 所做的事情。在 Emacs 中,运行应用程序的 Lisp 引擎与输入文本之间无缝结合。对 Emacs 来说,一切都是 Lisp 数据,因此一切都可以通过编程进行分析和操作。 这造就了一个强大的用户界面(UI)。但是,如果你是 Emacs 的普通用户,你可能对它的能力知之甚少。下面是你可能没有意识到 Emacs 可以做的六件事。 使用 Tramp 模式进行云端编辑 Emacs 早在网络流行化之前就实现了透明的网络编辑能力了,而且时至今日,它仍然提供了最流畅的远程编辑体验。Emacs 中的 Tramp 模式

How do I set the language in the racket REPL

微笑、不失礼 提交于 2020-03-18 10:51:24
问题 I would like to set the language that my racket REPL is using interactively, like this: -> #lang typed/racket ; readline-input:15:0: read: #lang not enabled in the current context [,bt for ; context] ; typed/racket: undefined; ; cannot reference undefined identifier ; [,bt for context]` But it gives me this error: -> ,bt ; typed/racket: undefined; ; cannot reference undefined identifier What is my error? 回答1: From the terminal you can choose what language to use when you start racket: racket

How to change this function, “car” got problems

微笑、不失礼 提交于 2020-03-03 11:55:08
问题 I want to write a function, which converts from a "normal" notation like this: "1+4*2-8" to this pre-notation: "+1-*428". I hope you get the point here. Important: It must be in Strings. What I get so far: (define (converter lst ) (let ((operand1 (car lst)) (operator (car (cdr lst))) (operand2 (caddr lst))) (list operator (converter operand1) (converter operand2))) ) (infixLst->prefixLst '(1 + 2 * 3)) I got two problems here. 1) It's for Lists, I need it work for Strings like "1+3" and not '

MiniKanren support by Dr Racket

ぐ巨炮叔叔 提交于 2020-02-28 04:03:08
问题 I started studying miniKanren with the book "The Reasoned Schemer - second edition" and the DrRacket scheme environment. I installed the "faster-minikanren" package, but the first examples of the book with the command run* (for example, (run* q #f) ) produce error messages such as run*: bad syntax in: (run* q #f) . Does this mean that the "faster-minikanren" package does not provide the right definition of minikanren? Or am I making a mistake? 回答1: As the readme says, you need to put (require

DrRacket - Display all the values in a list that are above average

依然范特西╮ 提交于 2020-02-26 02:15:30
问题 I'm creating a function that consumes a list of numbers and produces the elements in the list that are above average. Below is my code: (define (listlength list) (cond ((empty? list) 0) (else (+ 1 (listlength (rest list)))))) (define (listsum list) (cond [(empty? list) 0] [else (+ (first list) (listsum (rest list)))])) (define (average log) (/ (listsum log) (+ (listlength log) 1))) (define (average-filter log) (cons (cond [(> (first log) (average log)) (first log)] [else (average-filter (rest