Does SML/NJ 's Lazy work properly? - lazy-evaluation

I'm using SML/NJ v110.80 and Lazy.I tried the following code in repl
Control.lazysml := true;
open Lazy;
fun f x = f x;
let val x = $(f(4)) in 15 end;
The last expression should be 15 but it diverges.
Did I make a mistake or it just works improperly?
Thanks.
I find that it's my fault I should write
let val lazy x = $(f(4)) in 15 end;
I found this information here --http://www.geocities.jp/m_hiroi/func/smlnj16.html

Related

Is it safe to use math.Round instead of this Modf/Ceil/Floor combo

I'm in the progress of converting some Go code to C# and am wondering if the following piece of code:
_, x := math.Modf(frac)
if x >= 0.5 {
frac = math.Ceil(frac)
} else {
frac = math.Floor(frac)
}
would be any different to this:
frac = math.Round(frac)
I know rounding can sometimes be tricky so I wonder if the first snippit acts as a workaround for something.

Parallel operation hangs in scala

Scala noob here:
val pv = (1 to 100).toArray.par
Now I want to apply a map function to this parallel collection pv
pv.map(_ * 2)
However the above operation hangs. Any reason why?
Using Scala version 2.12.4 on a Mac OS X (High Sierra)
Seems this is caused by static initializer deadlock, see:
https://github.com/scala/scala-parallel-collections/issues/34
This issue point out in the repl, when create a parallel collection, repl will generate a wraper for it, when init, it will cause dead lock.
and it also can be reproduce in program from the:
https://github.com/scala/bug/issues/8119
object Foreacher {
val n = 0
val m = List(1).par.foreach(_ => n)
def main(args: Array[String]): Unit = println("Hello, all")
}

How to construct a loop in ATS over a given string?

For instance, how can I write code in ATS that traverses a given string as is done by the following C code:
while ((c = *str++) != 0) do_something(c);
Well, there is always a combinator-based solution:
(str).foreach()(lam(c) => do_something(c))
The following solution is easy, accessible and doesn't require any unsafe features (but it does use one advanced feature: indexed string type).
fun
loop {n:int}(p0: string(n)): void =
if string_isnot_empty (p0) then let
val c = (g0ofg1)(string_head(p0))
val p0 = string_tail(p0)
in
do_something(c); loop(p0)
end
Full code: https://glot.io/snippets/ejpwxk2xzx
The following solution makes use of UNSAFE but it should be really easy to access:
staload
UNSAFE =
"prelude/SATS/unsafe.sats"
fun
loop(p0: ptr): void = let
val c = $UNSAFE.ptr_get<char>p0)
in
if isneqz(c) then (do_something(c); loop(ptr_succ<char>(p0)) else ()
end
val () = loop(string2ptr(str))

Reapeat/until help in lua

Hello I've been trying to get this code to work, I even cheated and added in the goal to my code and its still not accepting my answer, any suggestions?
-- Functions...
function p() -- For user imput..
print("Enter # and try to get the closest to it! (Valid range is 1-100)")
local var = tonumber(io.read())
if var == nil then
var = 0
end
return var
end
--Start main code..
-- Initialize the pseudo random number generator (I'm on windows...)
math.randomseed( os.time() )
math.random(); math.random(); math.random()
-- Setting goal
goal = math.random(1,100)
-- Guessing loop...
repeat
g = p()
print(g)
print(goal)
until g == Goal
print("YOU GUESSED THE GOAL!")
Replace the G by a lower case g.
until g == goal

How to use if then else to build a string in a crystal reports formula

This is Crystal Reports 9 in Visual Studio 2003 by the way
Simple question about crystal reports formula syntax: How do I build the formula's result using if then clauses?
Specifically I would like something like this:
dim val as string
val = {table.level}
if {table.uom_id} = 5 then
val = val & ' feet'
else
val = val $ ' meters'
end if
and val should be the result of the formula.
As long as we're at it, are there any shortcuts for writing these? These are horribly verbose, the ternary operator would be very welcome.
Your example is close. Just use Crystal syntax, as shown here:
stringvar val := {table.level};
if {table.uom_id} = 5 then
val := val + ' feet'
else
val := val + ' meters';
//to return a value, just plop it down at the end
val
But if you want something a little more concise, use this:
if {table.uom_id} = 5 then
{table.level} + ' feet'
else
{table.level} + ' meters';

Resources