-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected behavior of Object doMessage #438
Comments
The : is not an operator by default in Io, which means in:
1 is not an argument of the colon. So it evaluates : which returns the pair and then continues to send the next message of 1 to that pair, which evals to 1 as numbers are cached messages. It can help to look at the message structure:
There is an operator table which can be used to adjust the list of operators and their precedence (looks like we need to add this to the docs). Here's a version using the global OperatorTable:
which evals as:
Btw, as the OperatorTable is global, I'd suggest a JSON parse(aString) method which uses Io to get a message structure and then manipulates it and evals it for the desired result, unless you really want to mix JSON syntax with Io code. |
Thanks, Steve! I'd started my implementation using UPD
Hmm... I'll try it this way. It plays nice with current |
It would be cool to support context specific parsing but I never got around to adding that as Io's parser wasn't really designed to be general, though it is remarkable how well it's able to handle turning most languages into a message tree which can then be massaged into the correct form. IIRC, Jeremy Treguna even wrote a C parser/evaluator that did this. |
Yeah, this is a really cool feature. I've seen others implementations of DSL's in Io including this C one. This is inspirational. Add a JSON parser just in about 20 lines of code... And this is actually without any overhead, without "parsing" in a traditional way, it's more like just definition of a syntactic sugar to Io itself. This feature also inspired me to add at least basic type checker to Io. But currently I'm involved in doing Io 1.0.0 and a lot of work is going to be done related to Eerie too, so I don't have much time for this at now... The more I work with current implementation of Io, the less I want to rewrite it in Rust. I'd rather concentrate my efforts on improving what already exists. And providing an interface to write addons in Rust. Still thinking about that. Back to the problem... I've just found Sandbox. If I modify the |
I had forgotten about Sandbox! I think that should work, but I'm not sure about the limitations on the returned references. I guess Thread could also be used in this way but you'd need to implement some communication and synchronization for it. |
Btw, it would be great to have an interactive debugger in situations like these. I wonder how hard it would be to get that working with MS Code. |
On OperatorTable, it might be nice if Compiler could have instances which each had their own operator table. |
Is there a repo for the Io in Rust project? I'd like to check it out. |
Not to hijack the discussion here, but making T foo := method(bar: T,
self: T
bar
) Then Object : := method(type,
if(self isKindOf(type),
self,
Exception raise("type mismatch")
)
) so that Doing this would have other implications, e.g. we might want Rational to be a Number clone so things can play nicely with either. There might also be scary consequences to redefining |
Originally, colon was treated as non-special character so we could have message names containing colons which would be convenient for Objective-C proxy calls. For example, we can call a method like this:
which would map to this on the Objective-C side to the equivalent of:
without having to translate the method signature name. I don't think the ObjcBridge ever got much use though, so it's less of a concern now but something to consider. |
I'll try then.
About two years ago I saw a GUI debugger in Io. Probably that was an example made by you. I hadn't brought it to live then because of some dependencies issue. There's a big lack in the language tooling in Io. I even couldn't find a good syntax plugin for vim (forked one and made it better, BTW: https://github.com/ales-tsurko/vim-io) That would be great to have things like linters and language servers, not only debugger.
Maybe I'll look into it, when I have more time.
Oh, sorry I was not clear. I haven't started this project yet. Just thinking about it. But it's already the third week I'm working on improvements for current (C) implementation of Io and Eerie. Basically, there's not much for Io: fix compilation issues, going to replace JSON parser as I've noticed here, configured CI (including Windows), maybe will configure CD too. For Eerie there's a whole new version: full refactoring, tests, a lot of fixes, ridding of environments and replacing them to "in-project dependencies" (similar to I was thinking about something similar for types syntax! But I'd put it in a namespace instead of reserving anything. So it would be possible to enable typing just for some parts or enable/disable it at runtime. Also, I'd make it a library.
Such consequences might have a place with anything in Io 😄 |
Just tested this code. I didn't explain how my code is organized. I have an I've replaced the content of Importer addSearchPath("io")
OperatorTable println # < - note this
Json OperatorTable println # and this
m := Json doString("""{ "h": 1 }""") The part of the output is:
So it looks like this way the operator definition is actually doesn't touch the global context! So that's it. Just need to make to hide this UPD Ah, no. That's because I didn't bring |
Might not be too hard to have the OperatorTable slot looked up via the context in which the String is parsed. IIRC, there is a context other than IoState, but I could be wrong. |
I just remembered that messages already check their own OperatorTable slot and only default to the global one if a local one isn't found. Usually it would find the one on the Message proto, which is assigned by the OperatorTable initialization code. (At least, this is what my Go implementation does; presumably I was |
Would be neat to expose the Lexer within Io, so aspects of token definitions could be modified. Just a little bit of control might go a long way. I guess we could just implement an Io lexer in Io for this as it wouldn't be much code. |
Isn't it already possible with |
Yes, I meant being able to inspect and change the grammar (or some instance of the grammar) http://iolanguage.com/guide/guide.html#Appendix-Grammar |
In the existing infra it seems like a lost feature 😄 I can only imagine how that would allow libraries for the syntax itself. Plugins for the programming language... Yeah, there're already things like JSX, but be able to do such things at runtime in such a simple manner is something new to me. |
I'm trying to implement a basic JSON parser in Io to get rid of parson dependency. It looks like a very easy task, but I faced a problem, which just blows my mind... Here's the code:
When I use this "library" in a script:
I get:
As you can see the Sequence's
:
method is called when it should and the message which this method gets is correct, but for some reason the result is always the last message in the chain. It's ignoring everything I return fromSequence :
. I tried a hard-coded value as well but no luck. What am I doing wrong?The text was updated successfully, but these errors were encountered: