scheme

In Scheme language, how to assign a variable counter in an inner do-loop connected with the outer do-loop?

对着背影说爱祢 提交于 2019-12-11 17:35:34
问题 I want to read 10 case files in Ansys Fluent and for each case file there are 10 data files to be read. Ansys Fluent uses Scheme programming language. I have to managed to get some answers to individual problems in the code here (Evaluating a floating point variable in Scheme language) and here (How to increase counter in a do-loop within Scheme language?), but when collecting the individual answers I realized that I need a new code for the counter which is used to read the data files through

List to dotted pair notation

你。 提交于 2019-12-11 16:35:41
问题 I am trying to write a simple Scheme function which convert given list to its dotted pair notation . For example if the input is - ((1 (2)) 3 ((4))) What will correspond to its dotted pair notation and what rules should be kept in the function to write such logic. Any such pointers will be truly grateful. 回答1: @Chris has given the right approach. Just make sure that printing the car and the cdr are actually recursive calls to your procedure: (define (display-dotted sexp) (cond ((null? sexp)

Having Trouble Returning the Deepest Pair of the List

試著忘記壹切 提交于 2019-12-11 15:51:50
问题 #lang racket (define (depth L) (cond ((null? L) 0) ;if list is null return 0, base case ((not(list? L)) 0) ;if list is just an atom also return 0, also a base case (else (max (+ 1 (depth(car L))) (depth(cdr L)))))) ;otherwise return the greater of recursive call (depth(car list)) +1 or (depth(cdr list)) ;the logic here using findMax is that to see which one of the recursion is deeper, and everytime car is called we add 1 to the depth I tried to implement a scheme to find the maximum depth of

(2d) perlin-noise: dot product of a gradient and a direction vector

*爱你&永不变心* 提交于 2019-12-11 15:04:17
问题 I am looking for a function that takes the coordinates of a current pixel and the coordinates of a corner (for a gradient), and returns the dot product of the gradient of that corner and the direction vector between the pixel and a corner. So the function would look like this: dot-grid-gradient: number number number number -> number 64 grids and 81 gradients: I already made a list of 81 gradients whose x and y coordinates were between 0 and 1 and all randomly generated. A gradient would be

Record error in Scheme/Racket - why do you need to define constructors as mutable?

江枫思渺然 提交于 2019-12-11 14:49:43
问题 i'm having trouble defining some code in scheme. I am trying to create a record for a node in Scheme/Racket, so far my code looks as follows: (define-record-type node (make-node v l r) node? (v tree-value) (l tree-left) (r tree-right)) However - when I try and execute I get the following error: define-record-type: expected a mutable', immutable', parent', protocol', sealed', opaque', nongenerative', or parent-rtd' clause in: (make-node v l r) I understand that you can define field types to be

How to increase counter in a do-loop within Scheme language?

倖福魔咒の 提交于 2019-12-11 14:15:30
问题 I want do a simple counter increase by one within a do-loop in Scheme language, but I'm not that familiar with the language and have tried many scripts without success. The code is going to be implemented in Ansys Fluent to read multiple case files: (define j 5) (Do ((i 10 (+ i 1))) ((>= i 20)) (ti-menu-load-string (format #f "/file/read-case \"C:/DataProcessing/Case~a-time~a-sec/test/Case~a-time~a-sec.cas\"" i j i j)) (set! j (+ j 1)) ) How to pass the new j value to the do-loop so that I

Operations using list elements

最后都变了- 提交于 2019-12-11 14:03:30
问题 I have a list in this format, (+ 2 3). Where the first character is a math symbol that can be applied to the other two elements. I cannot seem to get it to do the operations. I want to return 5 for the previous example. I've tried this: ((car '(+ 2 3)) (cadr '(+ 2 3)) (caddr '(+ 2 3))) But I get the following error: application: not a procedure. 回答1: You can try eval , should do it straight away: > (eval '(+ 1 2)) 3 If you'd like to have more control over the input, write a funcion: (define

“not a proper list” error in DrRacket writing Scheme

孤者浪人 提交于 2019-12-11 13:59:04
问题 I just follow the instructions at 3.3.3 of SICP to create the table. The code I wrote just works well. here is code_0.scm: #lang scheme (require rnrs/base-6) (require rnrs/mutable-pairs-6) (define (make-table) (list '*table*)) (define (assoc key records) (cond ((null? records) false) ((equal? key (caar records)) (car records)) (else (assoc key (cdr records))))) (define (insert! key value table) (let ((record (assoc key (cdr table)))) (if record (set-cdr! record value) (set-cdr! table (cons

Dynamically create FFI methods in Racket

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 13:59:00
问题 I'm playing with idea of loading С/Rust/etc functions via FFI in Racket. I'd like to specify list of function names as strings and then just load them by some helper function. Main problem is creating identifier/word from a string. For example, it is very simple in Rebol: foo: "test1" set to-word (rejoin [foo "_result_data"]) some print test1_result_data but in Racket I have to use syntax stuff. So I've found examples like How do I define functions using Racket macros? and Racket Macro to

using set! to change the value of a variable in drscheme

对着背影说爱祢 提交于 2019-12-11 13:57:46
问题 I'm trying to delete an occurrence of some value in a binary search tree. This is what I have so far: (define removeBin (lambda (x t) (cond ((< x (car t)) (removeBin x (cadr t))) ((> x (car t)) (removeBin x (caddr t))) ((equal? x (car t)) (if(and (null? (cadr t)) (null? (caddr t))) '() (let ((r (replacement t))) ((set! (car t) r) (removeBin r t)))))))) It's giving me the following error: set!: not an identifier in: (car t) What does that mean? and how can I fix it so that set! would work?