I am trying to type assert from a []Node
, to []Symbol
. In my code, Symbol
implements the Node
interface.
Here is some surrounding code:
43 func applyLambda(args []Node, env Env) Node {
44 if len(args) > 2 {
45 panic("invalid argument count")
46 }
47 fixed, rest := parseFormals(args.([]Symbol))
48 return Func{
49 Body: args[1],
50 FixedVarNames: fixed,
51 RestVarName: rest,
52 }
53 }
Here's the error I get:
./builtins.go:47: invalid type assertion: args.([]Symbol) (non-interface type []Node on left)
I'm sure there's a good reason for this. What's the best way to proceed?
[]Node
to[]Symbol
, but they didn't because it is too costly and such conversions aren't a common programming pattern. Theoretically, any conversion that does not entail a contradiction nor an issue makes sense - but language designers need to choose which conversions to put in the language. – Shortwave