sml

Generating a random number in SML

旧街凉风 提交于 2021-01-27 15:51:47
问题 How can you generate a random number from a specific range, for example the integer 34 in the range [1, 100]? I looked at the Random structure but it doesn't give me what I want, at least from what I can understand. 回答1: I think you have to use the Random structure in the given link like this ... - val nextInt = Random.randRange (1,100); - val r = Random.rand (1,1); - val x1 = nextInt r; - val x2 = nextInt r; 回答2: To get 34 integers between 1 and 100, you could use: let val seed = Random.rand

Does Python scoping rule fits the definition of lexical scoping?

主宰稳场 提交于 2020-11-29 02:54:58
问题 According to my programming language class, in a language that uses lexical scoping The body of a function is evaluated in the environment where the function is defined, not the environment where the function is called. For example, SML follows this behavior: val x = 1 fun myfun () = x val x = 10 val res = myfun() (* res is 1 since x = 1 when myfun is defined *) On the other hand, Python does not follow this behavior: x = 1 def myfun(): return x x = 10 myfun() # 10 since x = 10 when myfun is

Does Python scoping rule fits the definition of lexical scoping?

安稳与你 提交于 2020-11-29 02:53:24
问题 According to my programming language class, in a language that uses lexical scoping The body of a function is evaluated in the environment where the function is defined, not the environment where the function is called. For example, SML follows this behavior: val x = 1 fun myfun () = x val x = 10 val res = myfun() (* res is 1 since x = 1 when myfun is defined *) On the other hand, Python does not follow this behavior: x = 1 def myfun(): return x x = 10 myfun() # 10 since x = 10 when myfun is

Does Python scoping rule fits the definition of lexical scoping?

岁酱吖の 提交于 2020-11-29 02:52:05
问题 According to my programming language class, in a language that uses lexical scoping The body of a function is evaluated in the environment where the function is defined, not the environment where the function is called. For example, SML follows this behavior: val x = 1 fun myfun () = x val x = 10 val res = myfun() (* res is 1 since x = 1 when myfun is defined *) On the other hand, Python does not follow this behavior: x = 1 def myfun(): return x x = 10 myfun() # 10 since x = 10 when myfun is