mirror of
https://github.com/kanaka/mal.git
synced 2024-11-13 01:43:50 +03:00
io, swift3, vb: Add number?, fn?, macro?
This commit is contained in:
parent
85657c9632
commit
f18417417c
@ -83,6 +83,10 @@ MalCore := Object clone do(
|
||||
"symbol?", block(a, a at(0) type == "MalSymbol"),
|
||||
"keyword", block(a, MalKeyword with(a at(0))),
|
||||
"keyword?", block(a, a at(0) type == "MalKeyword"),
|
||||
"number?", block(a, a at(0) type == "Number"),
|
||||
"fn?", block(a, (a at(0) type == "Block") or
|
||||
((a at(0) type == "MalFunc") and (a at(0) isMacro not))),
|
||||
"macro?", block(a, (a at(0) type == "MalFunc") and (a at(0) isMacro)),
|
||||
|
||||
"pr-str", block(a, a map(s, s malPrint(true)) join(" ")),
|
||||
"str", block(a, a map(s, s malPrint(false)) join("")),
|
||||
|
@ -85,6 +85,25 @@ let core_ns: Dictionary<String,(Array<MalVal>) throws -> MalVal> = [
|
||||
default: return MV.MalFalse
|
||||
}
|
||||
},
|
||||
"number?": {
|
||||
switch $0[0] {
|
||||
case MV.MalInt(_): return MV.MalTrue
|
||||
default: return MV.MalFalse
|
||||
}
|
||||
},
|
||||
"fn?": {
|
||||
switch $0[0] {
|
||||
case MalVal.MalFunc(_, nil, _, _, _, _),
|
||||
MalVal.MalFunc(_, _, _, _, false, _): return MV.MalTrue
|
||||
default: return MV.MalFalse
|
||||
}
|
||||
},
|
||||
"macro?": {
|
||||
switch $0[0] {
|
||||
case MalVal.MalFunc(_, _, _, _, true, _): return MV.MalTrue
|
||||
default: return MV.MalFalse
|
||||
}
|
||||
},
|
||||
|
||||
"pr-str": {
|
||||
// TODO: if the following two statements are combined into one, we get
|
||||
|
27
vb/core.vb
27
vb/core.vb
@ -104,6 +104,30 @@ Namespace Mal
|
||||
End If
|
||||
End Function
|
||||
|
||||
Shared Function number_Q(a As MalList) As MalVal
|
||||
If TypeOf a(0) Is MalInt Then
|
||||
return MalTrue
|
||||
Else
|
||||
return MalFalse
|
||||
End If
|
||||
End Function
|
||||
|
||||
Shared Function fn_Q(a As MalList) As MalVal
|
||||
If TypeOf a(0) Is MalFunc AndAlso Not DirectCast(a(0),MalFunc).isMacro() Then
|
||||
return MalTrue
|
||||
Else
|
||||
return MalFalse
|
||||
End If
|
||||
End Function
|
||||
|
||||
Shared Function macro_Q(a As MalList) As MalVal
|
||||
If TypeOf a(0) Is MalFunc AndAlso DirectCast(a(0),MalFunc).isMacro() Then
|
||||
return MalTrue
|
||||
Else
|
||||
return MalFalse
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
' Number functions
|
||||
Shared Function lt(a As MalList) As MalVal
|
||||
@ -454,6 +478,9 @@ Namespace Mal
|
||||
ns.Add("string?", New MalFunc(AddressOf string_Q))
|
||||
ns.Add("keyword", new MalFunc(AddressOf keyword))
|
||||
ns.Add("keyword?", New MalFunc(AddressOf keyword_Q))
|
||||
ns.Add("number?", New MalFunc(AddressOf number_Q))
|
||||
ns.Add("fn?", New MalFunc(AddressOf fn_Q))
|
||||
ns.Add("macro?", New MalFunc(AddressOf macro_Q))
|
||||
|
||||
ns.Add("pr-str",New MalFunc(AddressOf pr_str))
|
||||
ns.Add("str", New MalFunc(AddressOf str))
|
||||
|
Loading…
Reference in New Issue
Block a user