iolanguage

Io language 'apply arguments'

安稳与你 提交于 2019-12-22 06:02:11
问题 In the Io programming language, is there an equivalent to lisp's apply function. So for example I have a method to wrap writeln : mymeth := method( //do some extra stuff writeln(call message arguments)) ) At the moment this just prints the list, and doesn't evaluate it's contents as if they were it's own args. 回答1: Thanks to that person who suggested evalArgs (not sure where your comment went). Anyway that has resolved for my situation, although unfortunately not in general I guess. You can

Io language 'apply arguments'

余生长醉 提交于 2019-12-22 06:01:15
问题 In the Io programming language, is there an equivalent to lisp's apply function. So for example I have a method to wrap writeln : mymeth := method( //do some extra stuff writeln(call message arguments)) ) At the moment this just prints the list, and doesn't evaluate it's contents as if they were it's own args. 回答1: Thanks to that person who suggested evalArgs (not sure where your comment went). Anyway that has resolved for my situation, although unfortunately not in general I guess. You can

How to define an xor operator in Io

偶尔善良 提交于 2019-12-11 12:26:50
问题 I'm working through Chapter 3, Day to of Seven Languages in Seven Weeks ("The Sausage King"). I've copied the code straight out of the book, but it's not working. Io 20110905 Add a new operator to the OperatorTable. Io> OperatorTable addOperator("xor", 11) ==> OperatorTable_0x336040: Operators 0 ? @ @@ 1 ** 2 % * / 3 + - 4 << >> 5 < <= > >= 6 != == 7 & 8 ^ 9 | 10 && and 11 or xor || 12 .. 13 %= &= *= += -= /= <<= >>= ^= |= 14 return Assign Operators ::= newSlot := setSlot = updateSlot To add

Io Language : Exception: Object does not respond to 'URL'

跟風遠走 提交于 2019-12-11 02:18:27
问题 Today I'm exercising an Io example of "seven language of seven weeks." Example code: futureResult := URL with("http://google.com/") @fetch writeln("Do something immediately while fetch goes on in background...") writeln("This will block until the result is available.") writeln("fetched ", futureResult size, " bytes") Running with exception: Io$ io future.io Exception: Object does not respond to 'URL' --------- Object URL future.io 1 CLI doFile Z_CLI.io 140 CLI run IoState_runCLI() 1 Directly

How do I convert a string to a list in Io?

牧云@^-^@ 提交于 2019-12-10 02:56:28
问题 For example, I'd like to turn "hello" into list(104, 101, 108, 108, 111) or list("h", "e", "l", "l", "o") So far I've created an empty list, used foreach and appended every item to the list myself, but that's not really a concise way to do it. 回答1: My own suggestion: Sequence asList := method( result := list() self foreach(x, result append(x) ) ) Haven't tested it performance-wise but avoiding the regexp should account for something. 回答2: Another nicely concise but still unfortunately slower

What's the significance of self inside of a method?

孤者浪人 提交于 2019-12-07 14:26:20
问题 I'm reading through Seven Programming Languages in Seven Weeks, and one of the problems states: How would you change / to return 0 if the denominator is zero? I first tried defining my own / and proxying its implementation to the original / method like this: Number oldSlash := Number getSlot("/") Number / = method(x, Number oldSlash(x)) However that was not working for me. After doing some Googling I found a similar piece of code. The code I found was using self in the implementation of the

What's the significance of self inside of a method?

天大地大妈咪最大 提交于 2019-12-06 03:46:32
I'm reading through Seven Programming Languages in Seven Weeks, and one of the problems states: How would you change / to return 0 if the denominator is zero? I first tried defining my own / and proxying its implementation to the original / method like this: Number oldSlash := Number getSlot("/") Number / = method(x, Number oldSlash(x)) However that was not working for me. After doing some Googling I found a similar piece of code. The code I found was using self in the implementation of the method. So, I tried using self and it seemed to work just fine: Number oldSlash := Number getSlot("/")

Io language 'apply arguments'

房东的猫 提交于 2019-12-05 11:11:27
In the Io programming language, is there an equivalent to lisp's apply function. So for example I have a method to wrap writeln : mymeth := method( //do some extra stuff writeln(call message arguments)) ) At the moment this just prints the list, and doesn't evaluate it's contents as if they were it's own args. Thanks to that person who suggested evalArgs (not sure where your comment went). Anyway that has resolved for my situation, although unfortunately not in general I guess. You can achieve what I describe by doing : writeln(call evalArgs join) This evaluates all arguments, and then joins