how about instead of prefixing all names with
unsafe we put them in an
Unsafe module, so that we can redefine
Unsafe for instance. elaboration:
(defmodule Unsafe (defmodule Array (defn nth [a i] ; do the thing ) ) ) (defn my-fun [a] (with Unsafe (println* (Array.nth a 0))))
this makes it explicit in both the call site and the definition, and the
with Unsafe block just looks good i think
(Array.reduce + 0 (Array.copy-map &Int.from-string &(lines &(trim-right &(IO.read-file "input")))))
(λ [r3, r3] r3)and
(Ref (λ [r1, &r2] r1))within
(Array.reduce + ... )))))."
&s but not having much luck, heh
&before the function you send as the first argument to reduce, so
&+in this case. But then you can't actually use
+for reducing, since the reducing function has to have signature
(Fn [a &a] a). So a quick lambda like
(fn [a b] (+ a @b))should solve that. Oh, and the third argument to reduce should also be a ref, so the complete oneliner is the following:
(Array.reduce &(fn [a b] (+ a @b)) 0 &(Array.copy-map &Int.from-string &(lines &(trim-right &(IO.read-file "input")))))
Array.reducecompletes too, right? Where in theory if there were another version of e.g.
(Array String)rather than
(Ref (Array String))the input could be freed earlier?
&are a bit annoying, yes, perhaps some of them can be avoided in the future, using lifetimes. Most of them are probably just necessary though, writing it as a
letmight make it more digestible in this case
It looks like this when it explodes:
Exception (0): epc1=0x40106122 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000 >>>stack>>> ctx: cont sp: 3ffffd10 end: 3fffffc0 offset: 01a0 3ffffeb0: 3fffdad0 3fffff90 3ffeec90 40201631 3ffffec0: feefeffe feefeffe feefeffe feefeffe 3ffffed0: feefeffe feefeffe feefeffe 3ffef404 3ffffee0: 00000000 00000000 00000000 00000000 3ffffef0: 40203685 00000001 3ffef41c 3ffee7b4 3fffff00: 3fffdad0 3fffff90 00000000 4020172e 3fffff10: feefeffe 00000001 3ffee74c 3ffee7b4 3fffff20: 00000000 00000000 00000000 00000000 3fffff30: 00012480 0000001c 00000000 3ffee7b4 3fffff40: 3fffdad0 40201782 00000008 40203c48 3fffff50: feefeffe 00000000 00000001 40201790 3fffff60: feefeffe feefeffe feefeffe feefeffe 3fffff70: feefeffe feefeffe feefeffe feefeffe 3fffff80: feefeffe feefeffe feefeffe feefeffe 3fffff90: 00000001 00000001 3ffef53c feefeffe 3fffffa0: feefeffe feefeffe 3ffee784 40202564 3fffffb0: feefeffe feefeffe 3ffe8508 40100449 <<<stack<<<
I guess someone very familiar with the esp8266 might be able to understand what's happening here but for me having a dump of memory doesn't help much :)
Yeah it's weird, the exception 0 is apparently IllegalInstructionCause but looking at the C code there doesn't seem to be any difference between allocating an array or a map and it handles the arrays just fine.
About the git repo what would be the right way of making the module in the file available? Is there a way to reexport it in the main file? Should I just load it in hoquet.carp and that will make it available to people who load the git repo?