I am currently trying to convert a code from mathematica to maxima. I keep coming across (* ::Input:: *) and i am not sure what it means. I would appreciate any help.
(* <anything> *) means comment.
Like /* <anything> */ in C++.
See the documentation here. You may also start here, with a search engine into Mathematica documentation.
Related
I'm trying to do my homework and hacking through some example code I saw this line:
[(:+ (:or VAR)) (token-VAR (string->symbol lexeme))]
This is from a lexical analyzer in a calculator;
Now I'm not really sure what either of this does, and I'm not particularly sure what this means exactly, but I'm pretty sure it has what I need to finish my homework. Searching hasn't gotten me any help so all help is great at this time. Thanks!
The sample code probably imported parser-tools using the : prefix (which is the recommended prefix in the parser-tools documentation. If that's the case, then :+ means "repetition one or more times" and :or matches any of the subpatterns (just VAR in this case).
I'm currently working through HtDP on my own.
In Chapter 5 "Symbolic Information" is covered. The example in the text is:
(define (reply s)
(cond
[(symbol=? s 'GoodMorning) 'Hi]
[(symbol=? s 'HowAreYou?) 'Fine]
[(symbol=? s 'GoodAfternoon) 'INeedANap]
[(symbol=? s 'GoodEvening) 'BoyAmITired]))
That's all clear. However, the second exercise asks:
Exercise 5.1.2. Develop the function check-guess. It consumes two numbers, guess and target. Depending on how guess relates to target, the function produces one of the following three answers: 'TooSmall, 'Perfect, or 'TooLarge.
Frankly, I don't really see when or why "symbol=?" comes in here. My solution only uses "cond". [EDIT: Code removed due to a suggestion since it is a solution to a textbook exercise.]
According to the text, "symbol=?" consumes two symbols and returns either true or false, depending on whether they are identical or not.
I fear that I am now deep into the realm of the Dunning-Kruger effect, but I really don't see a way to implement this piece of code with the use of "symbol=?". "cond" is covered in Chapter 4, which is why I am now confused.
Any help is highly appreciated.
If you want to have a look at the chapter in HtDP, then please go here:
http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-8.html#node_sec_5.1
Unfortunately, the solutions are only accessible with a password.
use < and > to compare the numbers. You can't to use symbol=? for this.
I came across the following piece of syntax in Racket, could anyone tell me what it means? I tried Googling it to no avail.
symbol=?
If you're using DrRacket, then hit F1 to find this documentation:
(symbol=? symbol1 symbol2 symbol3 ...) procedure
Returns #t if the symbols are the same, i.e., if their names are spelled the same.
I think that the confusion here is that symbol=? looks like some syntax for some weird expression. Racket follows Scheme and Lisp tradition where the syntax is pretty minimal: identifiers are very permissive, so this whole thing is just a name of a function. (And see rm's answer for what the function actually does.)
I'm trying to work my way through Compilers: Backend to Frontend (and Back to Front Again) by Abdulaziz Ghuloum. It seems abbreviated from what one would expect in a full course/seminar, so I'm trying to fill in the pieces myself.
For instance, I have tried to use his testing framework in the R5RS flavor of DrScheme, but it doesn't seem to like the macro stuff:
src/ghuloum/tests/tests-driver.scm:6:4: read: illegal use of open square bracket
I've read his intro paper on the course, An Incremental Approach to Compiler Construction, which gives a great overview of the techniques used, and mentions a couple of Schemes with features one might want to implement for 'extra credit', but he doesn't mention the Scheme he uses in the course.
Update
I'm still digging into the original question (investigating options such as Petit Scheme suggested by Eli below), but found an interesting link relating to Gholoum's work, so I am including it here.
[Ikarus Scheme](http://en.wikipedia.org/wiki/Ikarus_(Scheme_implementation)) is the actual implementation of Ghuloum's ideas, and appears to have been part of his Ph.D. work. It's supposed to be one of the first implementations of R6RS. I'm trying to install Ikarus now, but the configure script doesn't want to recognize my system's install of libgmp.so, so my problems are still unresolved.
Example
The following example seems to work in PLT 2.4.2 running in DrEd using the Pretty Big
(require lang/plt-pretty-big)
(load "/Users/donaldwakefield/ghuloum/tests/tests-driver.scm")
(load "/Users/donaldwakefield/ghuloum/tests/tests-1.1-req.scm")
(define (emit-program x)
(unless (integer? x) (error "---"))
(emit " .text")
(emit " .globl scheme_entry")
(emit " .type scheme_entry, #function")
(emit "scheme_entry:")
(emit " movl $~s, %eax" x)
(emit " ret")
)
Attempting to replace the require directive with #lang scheme results in the error message
foo.scm:7:3: expand: unbound identifier in module in: emit
which appears to be due to a failure to load tests-driver.scm. Attempting to use #lang r6rs disables the REPL, which I'd really like to use, so I'm going to try to continue with Pretty Big.
My thanks to Eli Barzilay for his patient help.
The language he uses is most likely Chez Scheme. Regardless, the R5RS language in PLT is a pretty strict version of R5RS, with extensions like square brackets throwing errors -- and you may get more mileage using the default #lang scheme language. (Or, if that fails, try and see if you can work with Petit -- the free version of Chez.)
You can see setup instructions for running it here on Ubuntu x86.
The installation download for Petite Scheme are here.
What does the following Guile scheme code do?
(eq? y '.)
(cons x '.)
The code is not valid in MzScheme, is there a portable equivalent across scheme implementations?
I am trying to port this code written by someone else. Guile seems to respond to '. with #{.}#, but I'm not sure what it means or how to do this in another scheme.
Okay, it seems that '. is valid syntax for (string->symbol ".") in Guile, whereas MzScheme at least requires |.| for the period as a symbol.
#{.}# is Guile specific way to define the symbol contains some delimiters of Scheme.
http://www.gnu.org/software/guile/manual/html_node/Symbol-Read-Syntax.html
For other Scheme dialect, there should be another way.
I'm surprised any Scheme system will accept a dot symbol at all. My advice is to use another symbol as (I'm sure you're aware) the dot is a shorthand to represent a pair, and even if you can find a Scheme that will take your code you will likely confuse anyone that has the unfortunate task of actually reading your code.