FAQ Database Discussion Community

Pair? function applying on Quote in Racket

scheme,racket,quote,sicp
In order to implement derivative of given polynomial, I need to factorize the polynomial, i.e., (* 3 x y) should be the product of 3 and (* x y). So I implemented a function multiplicand to get the second factor of a product: (define (multiplicand p) (let ((second-factor (cdr (cdr...

How do I use with-type to use Typed Racket fragments within untyped modules?

scheme,racket,typed-racket
The Typed Racket reference indicates that it's possible to use with-type to created “typed regions” within untyped code. The with-type form allows for localized Typed Racket regions in otherwise untyped code. It’s a little unclear how to actually use this, though. Obviously, using such a feature needs to take place...

Why does `-` parameter order cause Racket REPL to run out of memory?

scheme,racket
I'm seeing an issue when swapping the order of parameters to the - function. ; source (define (compose f g) (lambda (x) (f (g x)))) (define (repeated f n) (if (= n 1) f (compose f (repeated f (- 1 n))) ; causes an out of memory error (compose f...

racket. Implement the Ackermann's function

racket
I'm trying to understand, but so far I can not make myself. When I see the finished solution is easier to understand how to do it. This is my first exercise, the others want to do it myself, but need to understand how to implement it. Please help me how...

Generating n-grams with foldl in Racket

scheme,racket,fold
So I'm fiddling with Racket. Recursively generating n-grams from a list of words was pretty straightforward: (define (n-grams-recursive words n) (if (< (length words) n) '() (cons (take words n) (n-grams-recursive (cdr words) n)))) And the iterative version also pretty straightforward: (define (n-grams words n) (define (iter n-grams remaining-words) (if...

How to replace variable value inside cons cell in racket

scheme,racket
I would like to do something like this (cons '(someword,string->symbol somevarname) (restoflist)) but somevarname is never replaced by its value. I thought this was possible?...

Racket random function

scheme,racket
I'm having trouble with the random function. I have a function set up where: (define random-abcd (cond [(equal? (random 4) 0) 'A] [(equal? (random 4) 1) 'B] [(equal? (random 4) 2) 'C] [else 'D] )) However when I run this 'D comes out substantially more often than any of the...

abstracting away match in racket

racket
I have a couple of functions that matches for structs that look like such: (define (get-bounding-y struct-lst) (flatten (for/list ([i struct-lst]) (match i [(line _ _ _ _ _ y1 _ y2) (list y1 y2)] [(arc _ _ _ _ _ y radius _ _ _ _ _ _ _...

How to Merge 2 lists into one in racket

scheme,racket
I have 2 dynamic lists that I would like to merge into one. Say '(1 2 3 4) and '(15 16) and get '(1 2 3 4 15 16) How can this be done?...

Read Loop Over String in Racket Scheme

parsing,scheme,iteration,racket
I'm using Racket Scheme. I have a string defined and I'm attempting to parse it. I initially have (define expression (open-input-string "(expression here)")) And now I'm attempting to iterate over all the characters using the scheme read function. I'm new to scheme though and I'm not quite sure how to...

Transforming a function into a list in Drracket

scheme,racket
I create a function which create list. I want to use that list in an another function so how can I do this? (define (myfunc L n) (if (= n 0) empty (cons (list-ref L (random 26)) (myfunc L (- n 1))))) I want to assing this function as a...

Transforming origin of drawing context

racket
I am trying to transform a dc<%> instance in order to set the origin (0,0) to be the lower left hand corner. In principle, this question answers my question, however I am struggling to understand the detail of how it works as well as why I am seeing the behavior...

Is there a way to see the body of a lambda in Racket?

lambda,scheme,racket
Say I have this code: #lang racket (define a ((λ (x) x) ((λ (y) y) (λ (z) ((λ (w) w) z))))) I know intuitively that this lambda expression is (extensionally) equal to (λ (z) z) My question is if there is a way to print out the body of a...

Racket Sum of Perfect Roots Implementation

list,scheme,racket
I am trying to write a Racket function that takes in a list of numbers as the input, and outputs the sum of the square roots of those numbers in the list that are perfect squares. The code I have currently does not compile, and is as follows: (define (sum-of-perfect-roots...

Reverse list in Racket in O(n)

scheme,lisp,racket
I need to write a recursive function in Scheme which takes a list of atoms and reverses it in linear time. I am only allowed to use define, lambda, cons, car, cdr, cond, let, and null? . Here is what I have so far: (define reverse (lambda (lat) (cond ((null?...

What's the function to render scribble string with the environment in a hash table?

racket,scribble
I'm new to using scribble, but I can't work out how to use its syntax in my own programs, rather than using a scribble language. > (define ht (make-hash '(("Name" . "Simon")))) > (define template "Hello @Name") > (function-i-dont-know ht template) "Hello Simon" What is the function that I'm looking...

how to write lex file for input like “{\”a\“:1,\”b\“:2}”

json,parsing,racket,tokenize,lex
I want to implement a json parser, but having problem with parse object like "{\"a\":1,\"b\":2}", currently the parser output somthing like this '(json (object "{" (kvpair "\"a\":1,\"b\"" ":" (json (number "2"))) "}")) but what i actually want is '(json (object "{" (kvpair "\"a\"" ":" (json (number "1"))) "," (kvpair "\"b\""...

Using match with user defined types in PL Racket

racket
The following PL code does not work under #lang pl: Edited code according to Alexis Kings answer (define-type BINTREE [Leaf Number] [Node BINTREE BINTREE]) (: retrieve-leaf : BINTREE -> Number) (define (retrieve-leaf btree) (match btree [(Leaf number) number]) What i'd like to achieve is as follows: Receive a BINTREE as...

Racket - How to use foldr to evaluate if any element in a list satisfies an argument?

recursion,racket,fold
I have the task of writing a program called any? that requires an input of a list and one-argument procedure and then tells you if any element in that list satisfies the procedure. ex: (any? odd? (list 2 4 6 8)) -> false I need to use foldr in the...

Racket lists incompatible with r6rs?

list,scheme,racket,r6rs
I'm writing a program in which i have to reuse code from one of my professors. My program is written in Racket and the code i want to reuse is written in r6rs. When I want to test my program it always fails. This is because I call a procedure...

Find empy lines in text file

racket
I've been learning racket for a few days and I'm puzzled with this task, I'm trying to find empty lines in a text file and select a random empty line to INSERT the text "calculation here", this is as far as I have gotten so far. for example: myfile.txt has...

How to convert port to string and list in Racket?

scheme,racket
How do I convert all chars of a port to a string or a list so that I can operate on it as either a list of chars or a string? I was wondering if something similar to (define (port->list port) (list port)) is possible....

compare the length of two list and append in racket

functional-programming,racket
I've tried to write a function, merge_longer, in Racket that takes as input two lists, L1 and L2. If L1 is longer than L2 the function appends L2 to L1. Otherwise, it appends L1 to L2. (define L1 '(4 6 8 9)) (define L2 '(1 2 3)) (define (merge_longer L1...

“let” in Racket Matacircular Evaluator

scheme,racket,interpreter
I'm writing a metacircular evaluator in Racket and I'm having trouble with creating a syntactic abstraction for a let expression. I'm trying to create code for the body of a let, so essentially,(expand-let '(((a 1) (b 2)) (+ a b))) should produce '((lambda (a b) (+ a b)) 1 2)...

Check list for strings using string?

string,lisp,racket
Hi I am having a little trouble testing a list to see if the list contains only strings. I am reading the documentation 2.3(Iterations, and Recursion) + 3.12 (Conditionals) and I can't quite seem to work lists in the way that I want. I'm trying to keep it as simple...

scheme `promise?` Dr Racket, geiser

promise,racket,r5rs
Welcome to DrRacket, version 6.0 [3m]. Language: racket; memory limit: 128 MB. > promise? #<procedure:promise?> > (promise? (delay (+ 1 2))) #t I need to use R5RS and am working with delayed evaluation... here using geiser in emacs: [email protected]> (require r5rs) [email protected]> (cons 1 '()) (mcons 1 '()) ;; this...

Fastest way to join 2 lists?

scheme,racket
I'm making a program and in a very specific part I need to join 2 lists of objects. I've always used append to do such things but I've read that append it's not that fast. These two lists I need to join will eventually grow. So I'm looking for the...

Racket GUI, drawing text vertically, issues with “angle” argument

user-interface,text,racket,angle
I'm using the Racket GUI to write text in the window of my program. Until now I only needed to draw text horizontally. But now I would also want to write text vertically. I saw in the documentation we can give an "angle" argument when we send the message "draw-text"...

How to manually flatten a list in Racket (Scheme)

scheme,racket,flatten,list-processing
How could one go about flattening a list without using the flatten function built in to racket? I understand that the default implementation of flatten is (define (flatten lst) (cond ((null? list) empty) ((list? (car lst)) (append (flatten (car lst)) (flatten (cdr lst)))) (else (cons (car lst) (flatten (cdr lst))))))...

Join lists with overlap

scheme,racket
I'm trying to create a function that finds the area of overlap between two lists and returns the result of joining the two lists together. The overlap area is the longest suffix of the first list that matches a prefix of the second list and it only appears once in...

Create lists from lists

scheme,racket
I want to write a function which for n arguments will create n lists and each contains n-th element for every argument, for example: (aux '(1 2) '(3 4)) = `((1 3) (2 4)) I wrote such a function: (define (aux . args) (if (null? args) '() (cons (map car...

Racket\Scheme compare and delete unwanted items in a list

scheme,racket
I have 2 lists: (Define list1 '("xx1" "xx2" xx3" "xx4" "xx5")) (Define list2 '("xx2" "xx4" "xx5")) the items in the list above are just an example, but either way it will be a string item. What I need to do is compare both lists and remove the items in list1...

Unbound identifier racket operators

racket
This is my first time working with racket, and I am getting an error message (*: unbound identifier;) when trying to evaluate a list in Dr. Racket. #lang racket (define (randop) (define x(random 3)) (cond ((= x 0) '+) ((= x 1) '-) ((= x 2) '*) ) ) (define...

Racket Intersect Two Lists

list,scheme,racket
I am trying to intersect two lists on Racket, but the following code is not working: (define (intersection a b) (if (null? a) '() (if (contains (car a) b) (cond (car a)(intersection (cdr a) b)) (intersection (cdr a) b)))) The result always end up being the first item of list...

How to extract element from html in Racket?

scheme,racket
I want to extract the urls in reddit, my code is #lang racket (require net/url) (require html) (define reddit (string->url "http://www.reddit.com/r/programming/search?q=racket&sort=relevance&restrict_sr=on&t=all")) (define in (get-pure-port reddit #:redirections 5)) (define response-html (read-html-as-xml in)) (define content-0 (list-ref response-html 0)) (close-input-port in) The content-0 above is (element (location 0 0 15) (location 0 0...

Turn list of list into image

scheme,racket
Okay, so I am trying to turn a list of a list of numbers into an image where each number represents a block with a color assigned to that number. For example: (define allig '((1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

Finite state machine constructor - Racket Language

racket,fsm,dfa,finite-state-machine,nfa
I need to build a finite machine constructor that accepts all of the prefixes of a given machine's language. Let's say machine M1's language L(M1)= "abba" then the constructor should produce a new machine M2 such that L(M2)={empty, a, ab, abb, abba} Now there's a constructor in a library called...

How would I make this Racket code DRYer?

scheme,racket
I'm porting a Python script to Racket as a learning experience, and I have this function: (define (check-status) (define git [find-executable-path "git"]) (define-values (ckot out in err) (subprocess #f #f #f git "checkout" "-q" "master")) (define-values (local lout lin lerr) (subprocess #f #f #f git "rev-parse" "@")) (define-values (remote rout...

function enabling negative power in racket

recursion,functional-programming,racket
I'm trying to use a recursive function Power in Racket that takes as input two numbers x and y and returns xy, where x and y can be positive or negative. ;a power b (printf "Enter value of X: ") (define a (read)) (printf "Enter value of n: ") (define...

Dr Racket list function

scheme,racket
Define a procedure likenate that takes a list and returns the list with the symbol 'like inserted between each pair of adjacent elements in the given list. I feel like this should be really easy, but I keep getting lists of lists so the check-expects aren't working. I've been...

How to configure the Racket interpreter to support command history?

I've just set up Racket and have been trying out the interpreter. However, I can't seem to go up and down the command history using the arrows (or Ctrlp/Ctrln for that matter) or use Ctrlr to search through it. Is that even supported? Can I build it with that feature...

dr racket code error beginning student language

racket
I am writing a function that consumes two images and produces true if the first is larger than the second here is my code (require 2htdp/image) (check-expect(image1 30 40)false) (check-expect(image1 50 20)true) (define(image1 x y) (begin ( circle x "solid" "blue") (circle y "solid" "blue") (if(> x y) "true" "false")))...

Circular lists in Racket

list,racket,circular
It has been a while since i last programmed in Racket. Now i wanted to make a circular list in Racket as follows : (define x (list 1 2)) (set-mcdr! (cdr x) x) But this gives rises to the error : set-mcdr!: contract violation expected: mpair? given: '(2) argument position:...

Racket not closing TCP port

racket
I've written a simple HTTP echo server in Racket. When I run the server from within DrRacket and then click the Stop button, my program terminates, but the port that was being used takes an annoyingly long time to close. If I run lsof -i :<port> in my terminal after...

output variable value to new file

racket
Currently I have the following code: (define (write host code) (with-output-to-file host (lambda () (printf code)))) (let ([myself (find-system-path 'run-file)] [test (substring myself 1 3)]) (printf "~s\n" myself) (write "hello.txt" myself)) I'm trying to write the value of variable "myself". Sorry for being such a noob, I'm not a huge...

Racket: using big bang and on-click

scheme,lisp,racket
I've somehow been able to draw a small basic image in racket (a house). Now, what I'm stuck with is, using big-bang to draw the image -- and then being able to click the roof of the house and have it change to another color. This is what I have...

Converting string into lambda/value

scheme,eval,racket
I want the following code to work: (define fn.str "(lambda (x) (displayln x)") (define fn.callable (string->lambda fn.str)) ; and then 2 next lines should be valid (fn.callable 123) (apply fn.callable '(321)) But best I can get is to eval string and get output, instead my target is to get the...

Racket Scheme: Basic example with Swindle

scheme,racket
I wanted to write a small prototype for something, and one of my first thoughts was, that a multimethod-based implementation would be really cool. While I have used GOOPS in the past with guile, I thought I would give racket a try this time. And googling quickly showed that a...

All: A Function Returning True if and only if All Elements of a List are True

scheme,racket
I am looking for a built-in function in Racket that will return True iff all the items in a list are true. I tried: (define (all lst) (when (equal? lst '()) #t) (if (not (car lst)) #f (all (cdr lst)))) Giving error: car: contract violation expected: pair? given: '() A...

racket how to define function as another function in procedure

function,racket
I am trying to make a helper function that will take input of switched syntax. Helper function needs to be able to do: > (num sqr) ; where num=6, and sqr is the math function square. 36 Originally, the built-in syntax would be: >(sqr num) ; where num=6 36 Since...

(fixing a code for) racket— deleting a node from a tree

racket,binary-search-tree
So I'm currently stuck in the intermediate level of racket, and have looked at various codes, but most of them I can't figure out I'm trying to delete a node from a binary search tree So, I've so far come up with this, which includes an empty node and the...

Racket - outputting in numerical form the placement of a string within a list (from left to right)

recursion,boolean,racket
I've been tasked with creating a function that tells the placement in numerical form of a string within a list (from left to right), so that: (position "a" '("a" "b" "c" "d" "e")) returns 1 (position "b" '("a" "b" "c" "d" "e")) returns 2 and (position "z" '("a" "b" "c"...

Scheme - Access Data Pairs in List

scheme,racket
I am brand-new to Scheme (using Dr. Racket), and this is a homework assignment, so please no outright answers. I've been trying to find a solution online, but have not found one that is satisfactory. I am writing a procedure that will take one argument - a list of pairs....

understanding call/cc in scheme

scheme,racket,continuations
Could someone please explain what happens once the continuation is called for this. ((cdr (or (call/cc (lambda (cc) (cons 2 (lambda () (cc #f))))) (cons 3 5)))) ((cdr (or (call/cc (lambda (cc) (cons 2 (lambda () (cc #f))))) (cons 3 (lambda() (+ 3 2)))))) The first statement gives error but...

Writing a `define-let` macro, with hygiene

macros,racket,define-syntax,hygiene
I'm trying to write a define-let macro in racket, which "saves" the header of a (let ((var value) ...) ...) , namely just the (var value) ... part, and allows re-using it later on. The code below works as expected: #lang racket ;; define-let allows saving the header part of...

How do I require a library in PLT scheme (pre-racket)?

racket
I need to use a PLT-scheme library that only runs on a very old version of DrScheme (DrScheme v103p1), which I think is from at least 15 years ago. The problem I am having is that I can't figure out how to use the library in my code because aparently...

How do you get rid of those tick marks in command line Racket?

racket
Here's what I'm talking about: \$ racket > (list 1 2 3) '(1 2 3) It's an annoyance very similar to constructor-style printing. What it's showing is basically that (list 1 2 3) evaluates to (quote (1 2 3)). The gracket REPL doesn't do that (yet): \$ gracket -z >...

Scheme - Replacing elements in a list with its index

scheme,racket
I am trying to replace the elements in a scheme list with its position. For example, calling: (position '((a b) c)) should return: '((0 1) 2) So far, my code keeps the list format, but the index is not updating. (define (position term1) (define index 0) (cond [(null? term1) '()]...

Tail Recursion Understanding

recursion,scheme,racket
I was wondering if anyone could walk me through tail recursion. I have this procedure I made in Racket and I would like a simple explanation on what steps I should take to utilize what I have in the form of tail recursion. The code in Racket is as follows,...

Racket recursive function for returning the sum of a list of squared numbers

scheme,racket
I am new to Racket, and I am trying to write a recursive function that takes a number n and returns the sum of the squares of the first n integers. For example, (this-function 3) returns 14 because 14 is 9 + 4 + 1 + 0. I tried creating...

Scatter plot in racket with individual colors

plot,racket
I am exploring the plotting utilities in racket, and I have to say, so far I am incredibly impressed. However, I ran into a small difficulty. I was trying to make a scatter plot, where each point has its own color (for visualizing classification algorithms). However, I am not sure...

What exactly is a “continuation prompt?”

scheme,racket,continuations,delimited-continuations
I'm trying to decipher the documentation call-with-continuation-prompt Applies proc to the given args with the current continuation extended by a prompt. The prompt is tagged by prompt-tag, which must be a result from either default-continuation-prompt-tag (the default) or make-continuation-prompt-tag. The result of proc is the result of the call-with-continuation-prompt call....

Racket lexer - return list of cons

parsing,racket
I'm new to Racket but super excited about it. I've been working on writing a simple lexer for WWW-Authenticate headers. I'm feeling pretty good about the lexing, but now I'd like to change my output. #lang racket (require parser-tools/lex) (require (prefix-in : parser-tools/lex-sre)) (define in (open-input-string "MsRtcOAuth href=\"https://foo.com/WebTicket/oauthtoken\",grant_type=\"urn:microsoft.rtc:windows,urn:microsoft.rtc:anonmeeting,password\", Bearer trusted_issuers=\"\",...

Scheme struct with another struct

struct,scheme,racket,user-defined-types
I'm trying to learn scheme (drracket) by myself and I encountered a problem. I'm trying to work with different shapes such as circles , squares and rectangles. The task is the following: "Define the types "circle", "square" and "rectangle" and define the main-type "shape". I need the shape struct for...

Scheme - How do you apply data structures to the combining of 2 Roman Numeral objects (letters & values) to produce a 2-character Roman Numeral?

data-structures,scheme,racket
I'm attempting to solve the following problem: Write a function called form-rn that consumes two Roman-Numeral objects (digit1 and digit2) and produces the two-character Roman-Numeral represented by the values of digit1 and digit2 read from left to right. The string values of digit1 and digit2 must be a single letter...

Elegant Way Of Accounting For “A” When Converting Strings To 26-Ary And Back?

scheme,racket,base,hexavigesimal
I need to convert strings to 26-ary and then be able to convert them back. My current code is: (define (26-ary-word s) (let ([len (string-length s)]) (let f ([n 0] [acc (+ (- (char->integer (string-ref s 0)) 97) 1)]) ; adding 1 so that all strings start with 'b' (if...

racket: maximum height of a binary tree

tree,binary,height,racket,distance
I'm trying to create a code in racket that will find the maximum distance in a binary search tree from the root to a leaf. I've seen this done in C++ but am having trouble translating it to racket. I've managed to calculate all the nodes in a tree, but...

sicp pattern matching - compound?

scheme,racket,sicp
I am watching the video lectures of SICP. Currently I am on 4A Pattern Matching and Rule Based Substitution. So far, I found the Matcher and the Instantiator is easy. But I can't get my head into The simplifier. (define (simplifier the-rules) (define (simplify-exp exp) (try-rules (if (compound? exp) (map...

Why Is This Tail-Recursive Function So Much More Complicated?

recursion,racket,tail-recursion
So, I'm fiddling with some basic maths, and I wanted a function to convert between bases. I wrote this function: (define (convert-base from to n) (let f ([n n]) (if (zero? n) n (+ (modulo n to) (* from (f (quotient n to))))))) Which works for all my personal tests...

display executing name of the current running script

racket
I have tried a few methods, one of them being: (define (program) (find-system-path 'pref-file)) I have read from the documentation (after attempting the above code) and have noticed it is not what i'd need to use, obviously :) Any ideas? Would also like to save this information to a variables....

Racket random list-ref function

scheme,racket
Define a function that takes a non-empty list and returns an element of the list selected at random and with equal probability. (Do not use the built-in list-ref procedure.) I'm stuck on this. I feel like you would need to count the number of times the function has run...

Trying to write a recursion function in racket

recursion,scheme,racket,tail-recursion
I'm trying to write a regular recursion function and a tail-recursion function which takes four arguments and evaluates the sum of ax^2 + b for x from q to r. This is what I have so far and it is not working, can I get some information on what is...

How to get only specific elements of list in racket

functional-programming,scheme,racket
Input: '(("may 001" 75 72) ("may 002" 75 75) ("may 003" 70 73) ("june 101" 55 55) ("june 104" 55 54) ("aug 201" 220 220)) Desired output: '(("may 001" 75 72) ("may 002" 75 75) ("may 003" 70 73)) How do I achieve this? I only want the may terms....

Rename support for derived names in DrRacket

racket,rename,automated-refactoring
When a macro produces bindings using derived names, these are not considered references to the original name (which is expected behaviour). However, renaming doesn't work on the derived names. Here is a simple macro example: (define-syntax (my-syntax stx) (syntax-case stx () [(_ name) (with-syntax ([get-name (format-id #'name "get-~a" #'name)]) #'(begin...

require/typed contract in racket fails

scheme,racket,typed-racket
I've tried looking at the docs but i can't find an example that i can use for my case. I need to import break from srfi/1. Here's my attempt. The example works in #lang racket. #lang typed/racket (require/typed (only-in srfi/1 break) ;[break (All (T) (-> (-> T Boolean) (Listof T)...

Where can the Raco Pkgs library “table-editor” be downloaded?

racket,packages
I'm attempting to install this library for Racket, which depends on a library called table-editor. Helpfully, there is a comment in the source: ;; raco pkg install table-panel Unfortunately, that package doesn't seem to exist. Google is not returning helpful results. Does anybody know where to find it?...

Returning from a function inside when statement

scheme,lisp,racket
All I'm trying to do is use a when statement to return a value :( I want the functionality of: if(x) return y And I'm trying to use: (when (x) y) But the when statement is not evaluating in a way that exits the function and return y. It just...

Reverse the order of a given integer - Scheme

recursion,scheme,racket
ive been given a task in Scheme (Dr Racket) to reverse to order of a given digit. The solution should be recursive, and this is what i got this far.. The truth is, im not quite sure if the given algorithm even works because i get: " application: not a...

How to use symbols and lists in scheme to process data?

scheme,racket,grammar,bnf
I am a newbie in scheme, and I am in the process of writing a function that checks pairwise disjointess of rules (for the time being is incomplete), I used symbols and lists in order to represent the rues of the grammar. Uppercase symbol is a non-terminal in the grammar,...

DrRacket keyboard shortcut for α-rename

keyboard-shortcuts,racket,rename
How can I bind a keyboard shortcut (e.g. F2) to α-rename in DrRacket, available as rename foobar in the context menu brought up by right-clicking on a variable name? The documentation boils down to "call a magic function name from the API", but I'm having a hard time finding that...

How to express BNF using Lisp?

lisp,racket,grammar,bnf
I want to express a grammar rule that is written in BNF using Lisp. here is the rule. It is important to note that non-terminals are represented in capital letters and the terminals are represented in small letters: A -> a A b I tried to use the define function...

racket: counting number of siblings

list,tree,nested,racket,siblings
Having nested lists as the input, I'm trying to find how to output the number of 'siblings' an element has. In terms of trees, how many other leaf nodes belong to the same parent/root node. My code is giving the wrong outputs (it's a really bad code) and I'm not...

How do you reverse a sequence in Racket?

scheme,racket
I'm learning Racket just for fun. I've got a question. Is there a way to reverse a sequence? A sort of generic function for reversing things like: (sequence-reverse "Hello") (sequence-reverse '(1 2 3)) ...

racket - algorithm to cut din Ax

algorithm,racket
I´m developing a mini-game where I need to find out how many lines I can paint in a DIN-A0 paper if I get a DIN-Ax as input . For example: ;car horizontal and cdr vertical lines (define A1 (list 0 1)) (define A2 (list 1 1)) (define A3 (list 1...

Racket: inner reduction vs. lazy evaluation?

racket,lazy-evaluation,evaluation
I thought racket does inner reduction always for evaluation but I found out e.g. "if" (and cond?!) is lazy evaluation in racket...why is this needed? Is it impossible to realize an if-statement via inner reduction? I can not figure out where lazy evaluation is better than inner and vice versa?...

Mapping curry to a list of parameters

functional-programming,scheme,racket,currying
I'm doing some exercises in Racket, and ran into a problem I couldn't seem to query the docs for. I want to generate the following curries of modulo for a list of divisors: (define multlist '[3 5]) (define modfuncs (map (lambda x ;@ make some modulos (curry modulo x)) multlist))...

How to split a list into two parts in Scheme

scheme,racket
Example: (split '(1 2 3 4) '3) the Answer should be: ((1 2 3) 4) The function required 1 list and 1 number, the output should be nested list the nested list consist of all elements of "mylist" which are equal or less than the "num", and the greater number...

Racket/Scheme embed list within existing list

racket
I'm attempting to embed a list in to an existing list, the problem is explained below. list1 bla bla bla bla list2 useful stuff is here while my function iterates list1 it picks a random point where it will then insert: useful stuff is here the issue is that list2...

Call a method from a method

racket
I am pretty new to Racket. I am trying to write a program to return an index element in the list else, return the entire list. I have two separate methods: One recursive method to give index elements of the list if present else give the entire list. However, calling...

Max and min in Scheme

scheme,max,racket,min
I need to get the max and min of a list in scheme. I have the whole code but there is something wrong. I am not sure what, maybe with the parenthesis. Can anyone help? #lang racket (define (maxmin L) (cond ((null? L) '()) ((null? (cdr L)) (list (car L)...

How is it possible to filter a list of directories via “directory-exists?”?

scheme,racket
I recently discovered a strange behaviour of racket: Whenever I try to filter a list of directories created via directory-list my REPL returns me an empty list, but when I try the same with an quasiquoted list my REPL returns a correctly filtered list. My questions is now: Why it's...

Scheme full-house poke function

list,scheme,lisp,racket
I'm trying to define a function in Scheme that determines if a five-element list contains a full-house (that is, 3 elements are the same and the other 2 are the same, respectively). I have the outline in my head, although I'm messing up the syntax. I'm using and, let, to...

Conditional jump or move depends on uninitialised value(s) strcat

c,racket,tokenize
I understand that this valgrind error is occurred because I was trying to use something uninitialized. The code below is one that causes this error. What it's doing is it is trying to read Racket code and get each symbols such as + or define. (tokenize) I am not expecting...

Racket - Importing OpenCL

linux,scheme,opencl,racket
I am attempting to learn OpenCL and I installed the OpenCL FFI using raco pkg install opencl, but I am now getting a strange error when I try to use the package: clGetPlatformIDs: Undefined error: -1001 context...: /usr/share/racket/collects/racket/contract/private/arrow-val-first.rkt:255:18 /home/lb/Dropbox/workspace/misc/opencl-test.rkt: [running body] Here is the code snippet: #lang racket (require opencl/c)...

Can `match` in Racket have patterns with variables from an outer scope?

scope,scheme,pattern-matching,racket
Consider the following example: #lang racket (match '(cat . doge) [`(,a . ,b) (match b [a #t] [_ #f])] [_ "Not a pair"]) This is what I might write if I wanted to match pairs where the head and tail are the same. This doesn't work though because the second...

Racket: Graphing a parabola with elements from a list

list,function,plot,racket
I have created the following expression which I would like to graph parabolas based on the last two elements in a list. It looks like this: #lang racket (require plot) (define list-sqr-graph (lambda (lst) (cond [(null? lst) (plot (function sqr 0 0))] [(<= (car lst) 0) (list-sqr-graph (cdr lst))] [(not...

Item collection count - Racket/Sceme

count,functional-programming,scheme,racket,mud
I am in the process of designing a small MUD game using racket. In my game, gems which are collected by the player are used to bribe guards. Currently if the player possesses more than 1 gem, the game will not let them bribe a guard. Here is the relevant...