You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds what I'm calling prefix funcs. Sometimes it's nice to do something like:
list map.
lots of commands here..
..
..
end
So you know you're getting into a map right way as you read left to right and top to bottom.
<p>Prefix quotes work with any function that expects a quotation, including <code>map</code>, <code>filter</code>, <code>each</code>, and user-defined functions:</p>
160
+
161
+
<pre>
162
+
<code><spanclass="mshellLINECOMMENT"># Double each element</span>
This is also useful to turn boolean operators <code>and</code> and <code>or</code> into
185
+
a more traditional lookup infix format:
186
+
</p>
187
+
188
+
<pre>
189
+
<code><spanclass="mshellTRUE">true</span><spanclass="mshellPREFIXQUOTE">or.</span><spanclass="mshellFALSE">false</span><spanclass="mshellEND">end</span><spanclass="mshellPREFIXQUOTE">and.</span><spanclass="mshellTRUE">true</span><spanclass="mshellEND">end</span><spanclass="mshellLINECOMMENT"># Like (true | false) & true = true</span>
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: After executing the quotation in %s, the stack was empty.\n", t.Line, t.Column, t.Lexeme))
4267
+
}
4268
+
4269
+
ifresult.ShouldPassResultUpStack() {
4270
+
returnresult
4271
+
}
4272
+
4273
+
seconObjBool, ok:=secondObj.(MShellBool)
4274
+
if!ok {
4275
+
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: Expected a boolean after executing the quotation in %s, received a %s.\n", t.Line, t.Column, t.Lexeme, secondObj.TypeName()))
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: After executing the quotation in %s, the stack was empty.\n", t.Line, t.Column, t.Lexeme))
4296
+
}
4297
+
4298
+
ifresult.ShouldPassResultUpStack() {
4299
+
returnresult
4300
+
}
4301
+
4302
+
seconObjBool, ok:=secondObj.(MShellBool)
4303
+
if!ok {
4304
+
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: Expected a boolean after executing the quotation in %s, received a %s.\n", t.Line, t.Column, t.Lexeme, secondObj.TypeName()))
4305
+
}
4306
+
4307
+
stack.Push(MShellBool{seconObjBool.Value})
4308
+
}
4309
+
}
4310
+
default:
4311
+
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: Cannot apply '%s' to a %s and %s.\n", t.Line, t.Column, t.Lexeme, obj2.TypeName(), obj1.TypeName()))
4312
+
}
4313
+
4219
4314
} elseift.Lexeme=="return" {
4220
4315
// Return from the current function
4221
4316
returnEvalResult{
@@ -4225,7 +4320,6 @@ MainLoop:
4225
4320
ExitCode: 0,
4226
4321
ExitCalled: false,
4227
4322
}
4228
-
4229
4323
} else { // last new function
4230
4324
// If we aren't in a list context, throw an error.
4231
4325
// Nearly always this is unintended.
@@ -4637,87 +4731,6 @@ MainLoop:
4637
4731
default:
4638
4732
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: Cannot apply '-' to a %s and %s.\n", t.Line, t.Column, obj2.TypeName(), obj1.TypeName()))
4639
4733
}
4640
-
} elseift.Type==AND||t.Type==OR { // Token Type
4641
-
obj1, err:=stack.Pop()
4642
-
iferr!=nil {
4643
-
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: Cannot do '%s' operation on an empty stack.\n", t.Line, t.Column, t.Lexeme))
4644
-
}
4645
-
4646
-
obj2, err:=stack.Pop()
4647
-
iferr!=nil {
4648
-
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: Cannot do '%s' operation on a stack with only one item.\n", t.Line, t.Column, t.Lexeme))
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: After executing the quotation in %s, the stack was empty.\n", t.Line, t.Column, t.Lexeme))
4675
-
}
4676
-
4677
-
ifresult.ShouldPassResultUpStack() {
4678
-
returnresult
4679
-
}
4680
-
4681
-
seconObjBool, ok:=secondObj.(MShellBool)
4682
-
if!ok {
4683
-
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: Expected a boolean after executing the quotation in %s, received a %s.\n", t.Line, t.Column, t.Lexeme, secondObj.TypeName()))
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: After executing the quotation in %s, the stack was empty.\n", t.Line, t.Column, t.Lexeme))
4704
-
}
4705
-
4706
-
ifresult.ShouldPassResultUpStack() {
4707
-
returnresult
4708
-
}
4709
-
4710
-
seconObjBool, ok:=secondObj.(MShellBool)
4711
-
if!ok {
4712
-
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: Expected a boolean after executing the quotation in %s, received a %s.\n", t.Line, t.Column, t.Lexeme, secondObj.TypeName()))
4713
-
}
4714
-
4715
-
stack.Push(MShellBool{seconObjBool.Value})
4716
-
}
4717
-
}
4718
-
default:
4719
-
returnstate.FailWithMessage(fmt.Sprintf("%d:%d: Cannot apply '%s' to a %s and %s.\n", t.Line, t.Column, t.Lexeme, obj2.TypeName(), obj1.TypeName()))
0 commit comments