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

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, and lowercase is a terminal. I am trying to check if a rule passes the pairwise disjointness test.

I will basically check if a rule has only one unique terminal in it. if it is the case, that rule passes the pairwise disjointness test. In scheme, I am thinking to realize that by representing the terminal symbol in lower case. An example of that rule would be:

'(A <= (a b c))

I will then check the case of a rule that contains an or. like:

'(A <= (a (OR (a b) (a c))))

Finally, I will check recursively for non terminals. A rule for that case would be

'(A <= (B b c))

However, What is keeping me stuck is how to use those symbols as data in order to be processed and recurse upon it. I thought about converting the symbols to strings, but that did not in case of having a list like that for example '(a b c) How can I do it? Here is what I reached so far:

Best How To :

Pairwise Disjoint

As far as I know, the only way to check if a set is pairwise disjoint is to enumerate every possible pair and check for matches. Note that this does not follow the racket syntax, but the meaning should still be pretty clear.

It's not clear to me what else you're trying to do, but this is the going to be the general method. Depending on your data, you may need to use a different (or even custom-made) check for equality, but this works as is for normal symbols:

Symbols & Data

This section is based on what I perceive to be a pretty fundamental misunderstanding of scheme basics by OP, and some speculation about what their actual goal is. Please clarify the question if this next bit doesn't help you!

However, What is keeping me stuck is how to use those symbols as data...

In scheme, you can associate a symbol with whatever you want. In fact, the define keyword really just tells the interpreter "Whenever I say contains-match? (which is a symbol) I'm actually referring to this big set of instructions over there, so remember that." The interpreter remembers this by storing the symbol and the thing it refers to in a big table so that it can be found later.

Whenever the interpreter runs into a symbol, it will look in its table to see if it knows what it actually means and substitute the real value, in this case a function.

We tell the interpreter to keep the symbol in place rather than substituting by using the quote operator, ' or (quote ...):

]=> 'pairwise-disjoint?
;Value: pairwise-disjoint?

All that said, using define for your purposes is probably a really poor decision for all of the same reasons that global variables are generally bad.

To hold the definitions of all your particular symbols important to the grammar, you're probably looking for something like a hash table where each symbol you know about is a key and its particulars are the associated value.

And, if you want to pass around symbols, you really need to understand the quote and quasiquote.

Once you have your definitions somewhere that you can find them, the only work that's left to you is writing something like I did above that is maybe a little more tailored to your particular situation.

You can extend match. Custom patterns are defined with define-match-expander. Let's say you have the struct (struct line (x1 y1 x2 y2)) and you observe you are using the match pattern (line _ y1 _ y2) over and over. You prefer to write (line* y1 y2) Using define-match-expander you can...

This is the type I would assign to break: (require/typed (only-in srfi/1 break) [break (All [T] (-> (T -> Any) (Listof T) (Values (Listof T) (Listof T))))]) The predicate function can return anything. If it returns #f, it will be treated as falsy, and any other result will be treated...

As you've discovered, match and cases are two similar but separate things. The first is used for general Racket values, and the second is used for things that you defined with define-type. Unfortunately, they don't mix well in either direction, so if you have a defined type then you need...

In general there is no way to see body of a closure at runtime. The "body" is part of the source code. It gets compiled into bytecode (and later to machine code by the JIT). The closure consists at runtime of the captured values for the free variables in the...

DrRacket IDE In the Racket IDE you can hold CTRL with arrow keys to get to previously written statements in the interactions window. Racket in terminal eXtended REPL Extended REPL gives read-line features like using arrows to go back in history as well as you can search with CTRL+r. It...

What you wanted was an algorithm, so I made one: Suppose that you have that for A0 you can draw 0 horizontal lines (Which we'll call A0.hl) and 0 vertical lines (that we'll call A0.vl). Then for A1 you can draw A0.vl and (A0.vl*2)+1 horizontal and vertical lines respectively. Analogously...

The empty product is 1. The reason is that 1 is a neutral element for *. If you have the product of 2 and 3 and then multiply by the product of nothing, you will get 2*3*1 = 6. We can write (product (product 2 3) (product)) = (product 6...

You're correct that only the outer lambda form is applied to the argument 5. Then it returns its body with a replaced with 5, so it would return (lambda (b) (+ (sqrt 5) (sqrt b))) which is itself a function. This could later be applied to another argument, to produce...

The problem isn't the printf: > (printf "~s\n" (find-system-path 'run-file)) #<path:/Users/soegaard/racketgithub/racket/racket/bin/../DrRacket.app/Contents/MacOS/DrRacket> The problem is substring. The substring function expects a string as input, and gives an error, when it gets a path. You can let printf restrict the length of the output like this: > (parameterize ([error-print-width 20]) (printf "~.s\n"...

Given a file name, you can read it into a list of lines using file->lines. So for instance: (for ([line (in-list (file->lines "some-file"))]) (displayln (cond [(zero? (string-length line)) (make-random-line)] [else line]))) Where make-random-line is some function you define to return a random string, as you said you wanted to do....

Use filter for deleting from the list those objects whose confidence value matches the given number: (filter (lambda (e) (not (equal? (tv-conf (cog-tv e)) mi))) wordpairs) Conversely, this expression will return a list with those objects that do have the expected confidence (it's possible that there's more than one!) (filter...

Racket allows you to store values in the call stack. You can use this to keep track of the depth. Here is how I would do it: #lang racket ;;; This module holds the tools for keeping track of ;;; the current depth. (module depth racket (provide (rename-out [depth-app #%app])...

directory-list returns relative paths by default, which are later implicitly resolved with respect to the (current-directory), which might be different from the directory you passed to directory-list. Kind of like this: ~ $ ls dir file1 subdir2 ~ $ cat file1 cat: file1: No such file or directory From the...

IronScheme supports R6RS :) file-options are not available on with-output-to-file, so you need to use open-file-output-port. Example (not correct): (let ((p (open-file-output-port "robot-log.txt" (file-options no-create)))) (fprintf p "~a\r\n" whatToWrite) (close-port p)) Update: The above will not work. It seems you might have found a bug in IronScheme. It is not...

First of all, understand that Scribble is nothing more than a front-end for Racket code. All that Scribble does is take some input and output executable Racket code. This means that using the Scribble reader on your template string will just give you this: "Hello" Name Imagine that as plain...

To see what happens when ((lambda (x) (x x)) (lambda (x) (x x)) is evaluated use the stepper in DrRacket. It can show you the steps an evaluation takes. Write your expression in the definition window of DrRacket. Then choose the teaching language "Intermediate Student with lambda". Then click the...

Chris is correct. In the event you want to use rest arguments and then use it in recursion you should consider wrapping it in a named let or make a local helper procedure. (define (zip . args) (let aux ((args args)) (if (ormap null? args) '() (cons (map car args)...

If you are using tcp-listen directly (meaning that you handle all the low-level socket stuff yourself, and manually handle HTTP too), you need to call it with the reuse? parameter set to #t. If you are using the web-server module, it already sets reuse? to #t so it should already...

Pairwise Disjoint As far as I know, the only way to check if a set is pairwise disjoint is to enumerate every possible pair and check for matches. Note that this does not follow the racket syntax, but the meaning should still be pretty clear. (define (contains-match? x lst) (cond...

First of all, good for you for wanting to come up with a cleaner solution! You're right that there's a more elegant way to do what you've attempted. To start, using subprocess is almost certainly overkill in your particular use-case. The racket/system module provides a simpler interface that should be...

MIT/GNU Scheme should start off as minimized. It is just a background console window that starts the editor. You need not pay attention to it (nor can you interact with it). Edwin: *scheme* is the Edwin text editor, which looks to me like some sort of Emacs derivative. It allows...