comparison 2-Io/day3-DSL.io @ 46:eac30c1b92da

Add more notes and try to understand the operators
author IBBoard <dev@ibboard.co.uk>
date Wed, 20 Sep 2017 20:48:37 +0100
parents 8a2451a7b86e
children 409249712590
comparison
equal deleted inserted replaced
45:8a2451a7b86e 46:eac30c1b92da
40 call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\""), 40 call evalArgAt(0) asMutable removePrefix("\"") removeSuffix("\""),
41 call evalArgAt(1) 41 call evalArgAt(1)
42 ) 42 )
43 ) 43 )
44 44
45 # Note: Trailing commas break things in COMPLETELY CRYPTIC WAYS
46 # This is because we use doString, which executes it as a program,
47 # BUT the stack trace doesn't make this clear, so you end up chasing
48 # bugs in ENTIRELY THE WRONG PART OF THE CODE.
49 # Eval considered harmful.
45 the_string := "{ 50 the_string := "{
46 \"foo\": \"12345\", 51 \"foo\": \"12345\",
47 \"bar\": \"7890\", 52 \"bar\": \"7890\"
48 }" 53 }"
49 54
50 phoneNumbers := doString(the_string) 55 phoneNumbers := doString(the_string)
51 phoneNumbers keys println 56 phoneNumbers keys println
52 phoneNumbers values println 57 phoneNumbers values println
53 58
59 # It feels like implementing something like this should work,
60 # but it doesn't because "Number does not respond to ':'"
61 # because we assigned ":" as an assignment operator (like :=)
62 # and not as a normal operator, although it's then EVEN LESS CLEAR
63 # how the code in curlyBrackets works
64 # Also, Io Language docs are poor and don't make it clear how to:
65 # a) define a range that works; or
66 # b) do ANYTHING with the OperatorTable
67 Number atPutThing := method(
68 call println
69 return Range (call target) to(call evalArgAt(1))
70 )
71
54 # But presumably this will break, because there's no "atPutThing" method 72 # But presumably this will break, because there's no "atPutThing" method
55 a := 1 73 a := 1
56 b := 5 74 b := 5
57 range := a : b 75 range := a : b
58 # Yep - "Exception: Number does not respond to ':'" 76 # Yep - "Exception: Number does not respond to ':'"
59 # So you've got to be careful for reusable operators 77 # So you've got to be careful for reusable operators