Mercurial > repos > other > SevenLanguagesInSevenWeeks
changeset 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 |
files | 2-Io/day3-DSL.io |
diffstat | 1 files changed, 20 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/2-Io/day3-DSL.io Mon Sep 18 21:08:58 2017 +0100 +++ b/2-Io/day3-DSL.io Wed Sep 20 20:48:37 2017 +0100 @@ -42,18 +42,36 @@ ) ) +# Note: Trailing commas break things in COMPLETELY CRYPTIC WAYS +# This is because we use doString, which executes it as a program, +# BUT the stack trace doesn't make this clear, so you end up chasing +# bugs in ENTIRELY THE WRONG PART OF THE CODE. +# Eval considered harmful. the_string := "{ \"foo\": \"12345\", - \"bar\": \"7890\", + \"bar\": \"7890\" }" phoneNumbers := doString(the_string) phoneNumbers keys println phoneNumbers values println +# It feels like implementing something like this should work, +# but it doesn't because "Number does not respond to ':'" +# because we assigned ":" as an assignment operator (like :=) +# and not as a normal operator, although it's then EVEN LESS CLEAR +# how the code in curlyBrackets works +# Also, Io Language docs are poor and don't make it clear how to: +# a) define a range that works; or +# b) do ANYTHING with the OperatorTable +Number atPutThing := method( + call println + return Range (call target) to(call evalArgAt(1)) +) + # But presumably this will break, because there's no "atPutThing" method a := 1 b := 5 -range := a : b +range := a : b # Yep - "Exception: Number does not respond to ':'" # So you've got to be careful for reusable operators \ No newline at end of file