scheme

Multiplying each element of a list with each element of another list in Scheme programming

限于喜欢 提交于 2019-12-11 07:48:22
问题 i am trying to do the following in Scheme: List<int> list = new List<int>(); List<int> list1 = new List<int>(); List<int> list2 = new List<int>(); list.Add(1); list.Add(2); list.Add(3); list.Add(4); list1.Add(2); list1.Add(4); list1.Add(6); list1.Add(8); for (int i = 0; i < list.Count; i++) { for (int p = 0; p < list1.Count; p++) { list2.Add(list[i] * list1[p]); } } as seen in the code above, I am trying to multiply each element of the first list with every element in the second list. So 1*2,

Scheme collecting similar items in a list and finding most common item in a list [duplicate]

依然范特西╮ 提交于 2019-12-11 07:48:00
问题 This question already has answers here : Count occurrence of element in a list in Scheme? (4 answers) Closed 5 years ago . I want to make a function that occurs how many times an element occurs in a list. For example in the list: '(a b c b b c c a) I want it to return a nested list with: '((a 2) (b 3) (c 3)) I know the function will look sort of like this: (define collect-similar (lambda (elm ls) (cond [(null? ls) '()] [(equal? elm (car ls))] I know that I need to continue checking through

delete sublist by element occurrence (Scheme)

谁说我不能喝 提交于 2019-12-11 07:43:28
问题 How I could remove a sublist by searching only one elem from it. For example, let's have the list: ( (pacific (atlanta ohaio) (NY LI)) (atlanta (pacific blue) (ohaio green)) ) And I want to remove "pacific" from the list and to get: ( (pacific (atlanta ohaio) (NY LI)) (atlanta (ohaio green)) ) Any ideas would be greatly appreciated :). 回答1: The criteria for deleting an element from the input list is not stated clearly in the question. This will work for the example shown: (define lst '(

Replacing number by variable or loop in Scheme (Fluent) doesn't work

被刻印的时光 ゝ 提交于 2019-12-11 07:39:23
问题 I'm using the ANSYS Fluent program for CFD simulations. This program allows some partial automation of the simulation setup using a so-called Journal File, and I just came to know that this Journal File is written in Scheme. Unfortunately I never even heard of Scheme, I just know it's a Lisp dialect (which I also know nothing of). I'm trying to automate some boring tasks by using a loop to automatically set a bunch of parameters to my simulation. If I run this command from Fluent's command

Running code inside (do …) in Scheme (Fluent) executes differently than outside the loop

痴心易碎 提交于 2019-12-11 07:38:44
问题 A sequel to my previous question: I'm using the ANSYS Fluent program for CFD simulations. This program allows some partial automation of the simulation setup using a so-called Journal File, and I just came to know that this Journal File is written in Scheme. Unfortunately I never even heard of Scheme, I just know it's a Lisp dialect (which I also know nothing of). I'm trying to automate some boring tasks by using a loop to automatically set a bunch of parameters to my simulation. If I run

Create environment with variables in Scheme

梦想的初衷 提交于 2019-12-11 07:36:27
问题 I was looking to create something similar to an object or an environment kind of like in OOP This is what I was thinking: (define env (variable 'x 10 env)) Where I define an env and create a variable of value 10 in that environment. I also want to be able to call on the values in that environment. For example (get-value env 'x) > 10 The most I can understand is that it involves closures but i'm not sure where to start from there 回答1: The easiest way of achieving this is using alist. The above

Removing vowels from a String (Scheme)

随声附和 提交于 2019-12-11 07:33:56
问题 I know the basic algorithm for this problem but I am having trouble changing the sentence into a list inside my conditional. I created make-list to make it easier on myself but I'm not sure where to put it in the code. For ex, in the first cond statement, I need the sentence to be a list before I check if the first element in the sentence is a vowel.. but I have been doing it syntactically wrong. vowel-ci? returns #t if a character is a case insensitive vowel, and #f otherwise. stenotype

Zip function in typed racket with rest arguments

那年仲夏 提交于 2019-12-11 07:26:30
问题 I'm struggling with the syntax for a function that zips together any number of lists. I currently have: (define (zip . [lsts : (Listof Any) *]) (apply map (inst list Any) lsts)) Which causes the following error when evaluated: Error: struct:exn:fail:syntax /Applications/Racket v6.6/collects/racket/private/kw.rkt:929:25: Type Checker: Bad arguments to function in `apply': Domains: (-> a b ... b c) (Listof a) (Listof b) ... b (-> a c) (Pairof a (Listof a)) Arguments: (-> Any * (Listof Any))

Pairing 2 lists Scheme

六月ゝ 毕业季﹏ 提交于 2019-12-11 07:23:52
问题 SCHEME/Racket/R5RS Attempting to make a recursive procedure that pairs 2 lists of the same size. Just cant get the recursive call right. This is what I have and I am stuck. (define (pairs list1 list2) (if (or (null? list1) (null? list2)) '() (cons (car list1) (car list2)) )) Test Case: (pairs '(1 2 3) '(a b c)) Desired Output: ((1 . a) (2 . b) (3 . c)) Current Output: (1 . a) 回答1: You just have to cons the current result to the recursive call of the procedure, and that's it! (define (pairs

Why is this expression giving me a function body error?

谁说我不能喝 提交于 2019-12-11 07:18:23
问题 (define (subtract-1 n) (string-append "Number is: " (number->string n)) (cond [(= n 0) "All done!"] [else (subtract-1(- n 1))])) I keep getting the error: define: expected only one expression for the function body, but found 1 extra part. I'm not understanding why I'm getting this. NOTE TO SELF: When using DrRacket, Setting the language to BSL may make Racket commands error at compile time. 回答1: The language you're using (BSL) only allows a single expression inside the body of a procedure, if