smlnj

How to do bitwise AND in SML/NJ?

会有一股神秘感。 提交于 2019-12-01 20:41:30
Need it for a program I'm writing (repeated squaring to comput x^n). I can't seem to find the syntax for it, or if it is even supported. They're available within the Word8 and Word structures . let open Word8 infix andb orb xorb notb << >> ~>> in print (Word8.fmt StringCvt.BIN 0wxF) (* 1111 *) ; print "\n" ; print (Word8.fmt StringCvt.BIN 0wxA) (* 1010 *) ; print "\n" ; print (Word8.fmt StringCvt.BIN (0wxF andb 0wxA)) (* 1010 *) ; print "\n" end 来源: https://stackoverflow.com/questions/35742341/how-to-do-bitwise-and-in-sml-nj

Multiple Patterns in 1 case

試著忘記壹切 提交于 2019-12-01 18:37:32
In SML, is it possible for you to have multiple patterns in one case statement? For example, I have 4 arithmetic operators express in string, "+", "-", "*", "/" and I want to print "PLUS MINUS" of it is "+" or "-" and "MULT DIV" if it is "*" or "/" . TL;DR: Is there somewhere I can simplify the following to use less cases? case str of "+" => print("PLUS MINUS") | "-" => print("PLUS MINUS") | "*" => print("MULT DIV") | "/" => print("MULT DIV") Given that you've tagged your question with the smlnj tag, then yes, SML/NJ supports this kind of patterns. They call it or-patterns and it looks like

Horner's rule for two-variable polynomial

末鹿安然 提交于 2019-12-01 18:01:36
Horner's rule is used to simplify the process of evaluating a polynomial at specific variable values. https://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation#Standard_ML I've easily applied the method using SML, to a one variable polynomial, represented as an int list: fun horner coeffList x = foldr (fn (a, b) => a + b * x) (0.0) coeffList This works fine. We can then call it using: - val test = horner [1.0, 2.0, 3.0] 2.0; > val test = 17.0 : real Where [1.0, 2.0, 3.0] is the list representing the polynomial coefficients, 2.0 is the value of the variable x, and 17.0 is the

Suppress “val it” output in Standard ML

二次信任 提交于 2019-12-01 03:40:28
I'm writing a "script" in Standard ML (SML/NJ) that sets up the interactive environment to my liking. The last thing the script does is print out a message indicating everything went smoothly. Essentially, the last line is this: print "SML is ready.\n"; When I run the script, all goes well but the SML interpreter displays the return value from the print function. SML is ready. val it = () : unit - Since I'm merely printing something to the screen, how can I suppress the "val it = () : unit" output so that all I see is the "SML is ready" message followed by the interpreter prompt? To surpress

How do I install a working version of Standard ML on Mac?

断了今生、忘了曾经 提交于 2019-12-01 00:34:46
I'm using Mac OSX 10.7.5 and I can't seem to get download a working Standard ML compiler with a REPL available. Is this supposed to be so difficult? Is there a best ML that I should be downloading. I've tried SML/NJ and MLton to no avail. I did the following: --download appropriate(for your operating system) .dmg file from http://www.smlnj.org/dist/working/110.75/ --in your ~/.bash_profile: export PATH="$PATH:/usr/local/smlnj-110.75/bin" --run your bash_profile by doing source .bash_profile --go to terminal and type sml. I personally use sml mode for emacs. Add the following to your .emacs

What does this function signature mean in sml?

核能气质少年 提交于 2019-12-01 00:23:09
I'm looking through some notes that my professor gave regarding the language SML and one of the functions looks like this: fun max gt = let fun lp curr [] = curr | lp curr (a::l) = if gt(a,curr) then lp a l else lp curr l in lp end Could someone help explain what this is doing? The thing that I am most confused about is the line: let fun lp curr [] = curr What exactly does this mean? As far as I can tell there is a function called lp but what does the curr [] mean? Are these arguments? If so, aren't you only allowed one parameter in sml? It means that lp is a function that takes 2 parameters,

How to disable SMLNJ warnings?

两盒软妹~` 提交于 2019-11-30 17:29:48
问题 I'm trying to write command line scripts, but SML's warnings obfuscate the interface. The docs say to use: Compiler.Control.printWarnings := false; But SMLNJ has since renamed these to: Control.printWarnings := false; Which actually produces even more printouts. Example: $ cat hello.sml print "Hello World!\n"; OS.Process.exit(OS.Process.success); $ sml hello.sml Standard ML of New Jersey v110.72 [built: Mon Nov 14 17:30:10 2011] [opening hello.sml] Hello World! val it = () : unit [autoloading

Open file in ML(SMLNJ)

旧时模样 提交于 2019-11-30 09:54:00
问题 I need to read file in ML (SLMNJ) and save it in some structures. I need to read some data that points to graph declaration: [( 1 , 2 , 13 ),( 2 , 3 , 3 ),( 2 , 4 , 8 ),( 2 , 5 , 4 ),( 3 , 1 , 5 ),( 3 , 4 , 1 ),( 4 , 6 , 5 ),( 5 , 5 , 5 ),( 6 , 4 , 6 )] (first number: name of the node , secend number: name of connected node , third number weight for this mane (each () show one mane ) ) for expamle this is test input how to read file and which structure to save it 回答1: for reading from file

What are the options SOME and NONE in SML?

萝らか妹 提交于 2019-11-30 09:14:51
问题 I am new to SML (and programming, actually). fun readlist (infile : string) = let val ins = TextIO.openIn infile fun loop ins = case TextIO.inputLine ins of SOME line => line :: loop ins | NONE => [] in loop ins before TextIO.closeIn ins end ; This is a program I encountered here. How do I use SOME and NONE, and how to use 'before'? 回答1: The option data type is used if there is a possibility of something having no valid value. For instance, fun divide x y = if y == 0 then NONE else SOME (x /

How to 'fix' the SML/NJ interactive system to use Arrow Keys

天大地大妈咪最大 提交于 2019-11-30 03:45:20
I'm having some trouble using SML/NJ interactive system, namely, that when I try to use my arrow keys (either left or right to make a correction in the expression I've typed, up to repeat the last expression), my Terminal prints codes. (e.g. ^[[A for up ^[[D for left, etc.). While I can still use the system, it makes it very tedious. I've looked around in Control.Compiler, is there something I'm missing? For whatever its worth, I'm using the Mac Terminal. Thanks ^_^ Try this. You can use socat to add readline support to many things: socat READLINE EXEC:sml I just realized you're on OS X. socat