[QUOTE=Darwin226;25086444]Are there no disadvantages? Is there any benefit from writing a full name?[/QUOTE]
Nope.
Wasn't <= supposed to immediately return? Why doesn't this work then? :saddowns:
[code]>> (str -> if true (<= str) "nope") => test
=> (function)
>> test "yep"
=> nope[/code]
[QUOTE=raBBish;25086809]Wasn't <= supposed to immediately return? Why doesn't this work then? :saddowns:
[code]>> (str -> if true (<= str) "nope") => test
=> (function)
>> test "yep"
=> nope[/code][/QUOTE]
For starters, the return value must precede <=.
Secondly, the <= only returns from the current function, in this case the one passed to if. That's pretty useless, and I'll commit a workaround soon.
[QUOTE=turb_;25086897]For starters, the return value must precede <=.
Secondly, the <= only returns from the current function, in this case the one passed to if. That's pretty useless, and I'll commit a workaround soon.[/QUOTE]
Alright, thanks for explaining.
[editline]04:22PM[/editline]
[code](b1 -> (b2 ->
if_else b1 (
if_else b2 (
true
) (
false
)
) (
false
)
)) => and
(b1 -> (b2 ->
if_else b1 (
true
) (
if_else b2 (
true
) (
false
)
)
)) => or
put and true true
put and true false
put or true false
put or false false[/code]
:v:
[QUOTE=Darwin226;25086444]Are there no disadvantages? Is there any benefit from writing a full name?[/QUOTE]
The "var" keyword invokes type-inference. It means the variable is still fully typed, but the actual type is inferred from the initializer. Hence to use "var", you need to declare & initialize in one statement, after that, the variable has a static type and has no effect on what happens at run-time (unlike the "dynamic" keyword).
I've actually heard a lot of C# programmers complain about the use of "var" because they think it causes inconsistencies and ambiguities in your code.
Just trying to give the whole story here, personally I think that's rubbish and "var" is a god-send in an otherwise quite verbose language.
(Many other languages have type-inference, most notably C++0x has the same behaviour with "auto")
So actually using var is nothing more than a shortcut to writing the whole type before the name?
Nifty.
[QUOTE=raBBish;25086933]Alright, thanks for explaining.[/QUOTE]
Did this for you:
[release][b]New syntax[/b]
You can now repeat the '<' in the <= operator to return through multiple functions.
[img]http://ahb.me/x7g[/img]
<= is regular return, <<= returns the function that called the current function, and so on.
You'll need to update your copies to use this feature.
[/release]
It's up on Try Kari too.
[editline]11:55PM[/editline]
I don't know if I should be proud of how I achieved that feature or not...
[cpp]
if (Tokens[i] is ReturnToken)
throw new ReturnFromFunction(((ReturnToken)Tokens[i]).Levels - 1, val ?? NilValue.Nil);
// ...
try
{
val = FunctionStack.Pop().Call(val);
}
catch (ReturnFromFunction r)
{
if (r.ReturnsLeft > 0)
throw new ReturnFromFunction(r.ReturnsLeft - 1, r.Value);
val = r.Value;
}
[/cpp]
[QUOTE=turb_;25087401]I don't know if I should be proud of how I achieved that feature or not...
[/QUOTE]
Clever use of exceptions there.
I might use this in my C# game engine, with your permission of course. :3:
Since the syntax is really similar to traditional (Source) console commands, it would be useful for a developer console.
[QUOTE=raBBish;25087564]I might use this in my C# game engine, with your permission of course. :3:[/QUOTE]
[url=http://github.com/charliesome/Kari/blob/master/readme.md]I gave my permission here[/url] :p
[QUOTE=turb_;25087401]I don't know if I should be proud of how I achieved that feature or not...
[cpp] if (Tokens[i] is ReturnToken)
throw new ReturnFromFunction(((ReturnToken)Tokens[i]).Levels - 1, val ?? NilValue.Nil);
// ...
try
{
val = FunctionStack.Pop().Call(val);
}
catch (ReturnFromFunction r)
{
if (r.ReturnsLeft > 0)
throw new ReturnFromFunction(r.ReturnsLeft - 1, r.Value);
val = r.Value;
}
[/cpp][/QUOTE]
I don't think you should as that is not what exceptions are intended for. Could you not just return a struct{ bool totalReturn; returnval val; } from the Call-method and check for totalReturn?
Will this work fully on Mono? I know that it doesn't have quite the ability of the .NET systems.
[QUOTE=Qombat;25106698]Will this work fully on Mono? I know that it doesn't have quite the ability of the .NET systems.[/QUOTE]
Kari is targeted at .NET 4, which is (afaik) currently unsupported by Mono. .NET 4 support will be present in Mono 2.8, and is available in the [url=http://github.com/mono/mono]Mono repository[/url].
I don't believe I'm using any .NET 4 features, so I'll retarget Kari to 3.5 (supported by Mono), run a few tests and if it all works, I'll retarget the whole thing to .NET 3.5.
[QUOTE=turb_;25106881]Kari is targeted at .NET 4, which is (afaik) currently unsupported by Mono. .NET 4 support will be present in Mono 2.8, and is available in the [url=http://github.com/mono/mono]Mono repository[/url].
I don't believe I'm using any .NET 4 features, so I'll retarget Kari to 3.5 (supported by Mono), run a few tests and if it all works, I'll retarget the whole thing to .NET 3.5.[/QUOTE]
What are the new features anyways? I think I only used Tuples that were unsupported until 4.0.
[QUOTE=Darwin226;25106931]What are the new features anyways? I think I only used Tuples that were unsupported until 4.0.[/QUOTE]
Dynamic variables, optional parameters and named parameters at least.
[editline]04:49PM[/editline]
Anyways, I just tested and it works perfectly running under Mono 2.6.7 after re-targeting to 3.5 and removing Microsoft.CSharp reference.
[img]http://localhostr.com/files/050083/MonoKari.png[/img]
[QUOTE=raBBish;25107111]Anyways, I just tested and it works perfectly running under Mono 2.6.7 after re-targeting to 3.5 and removing Microsoft.CSharp reference.
[/QUOTE]
Did you test it on Linux, too? :3:
[QUOTE=raBBish;25107111]Dynamic variables, optional parameters and named parameters at least.[/quote]
The latter two are C# 4 features.
.NET 4 introduced covariance in generics, which I wasn't sure if the marshaling stuff relied on.
So I was writing up a suite of tests for Kari, which included a test similar to this:
[cpp]
[TestMethod]
public void NonObjectAsObject()
{
Test.Throws<RuntimeException>(() => Evaluate(@"1.test"));
}
[/cpp]
I wasn't deliberately trying to break anything, I was just trying to get a few tests up and working.
When I ran the tests, expecting them to all pass, I got this:
[img]http://ahb.me/xQV[/img]
Unit Tests are great :v:
[editline]03:51PM[/editline]
[QUOTE=raBBish;25084484]I tried :v:
[code](n ->
put n
if lt n 2 (n)
if eq n 2 (add fib sub n 1 fib sub n 2)
if gt n 2 (add fib sub n 1 fib sub n 2)
) => fib[/code]
No idea if it works, it times out on the website and I'm too lazy to test with the real version.[/QUOTE]
Turns out this works (with a minor modification), and I'm using it in a unit test! (I hope that's alright with you)
[cpp]
[TestMethod]
public void Fibonacci()
{
var val = Evaluate(@"
(n ->
put n
if lt n 2 (n <<=)
if eq n 2 (add fib sub n 1 fib sub n 2 <<=)
if gt n 2 (add fib sub n 1 fib sub n 2 <<=)
) => fib
fib 9");
Assert.IsInstanceOfType(val, typeof(NumberValue));
Assert.AreEqual(34, ((NumberValue)val).Number);
}
[/cpp]
What happened to if_else? :ohdear:
Does Try Kari support <<= yet?
[img]http://dl.dropbox.com/u/1106779/TryKariBug.PNG[/img]
[QUOTE=Robber;25127776]Does Try Kari support <<= yet?[/QUOTE]
[img]http://localhostr.com/files/ef44e1/karistuff.png[/img]
Yes, but there's something else going on...
[img]http://localhostr.com/files/e97664/errorkari.png[/img]
Ahh yes, closures were recently broken.
They've been fixed, but I forgot to update Try Kari. Hold on, I'll fix it now.
[editline]10:03PM[/editline]
Fixed:
[img]http://ahb.me/x_y[/img]
I solved the first Project Euler problem :buddy:
[code](n-> (m-> if m (if n (true <<<=))<=false))=>and
0 => i 0=> sum while (lt i 500)(if eq mod i 3 0 (add sum i => sum) if and eq mod i 5 0 not eq mod i 3 0 (add sum i => sum) add i 1 => i) put sum
while (lt i 1000)(if eq mod i 3 0 (add sum i => sum) if and eq mod i 5 0 not eq mod i 3 0 (add sum i => sum) add i 1 => i) put sum[/code]
I had to split the loop in two lines because it always timed out.
[url]http://downforeveryoneorjustme.com/http://trykari.charliesomerville.com/[/url]
Oh god what did I kill try kari :ohdear:
[editline]04:00PM[/editline]
[code]>> (n->mul 2 n) 2
=> 2[/code]
What is going on o_O
[QUOTE=esalaka;25128509]
[code]>> (n->mul 2 n) 2
=> 2[/code]
What is going on o_O[/QUOTE]
Can't call a function like that.
If you really want to, you need to dereference it first:
[code]
>> (x -> x) => deref
=> (function)
>> deref (n -> mul 2 n) 2
=> 4
[/code]
It displays two because 2 is the last value evaluated in that expression.
[editline]11:16PM[/editline]
[QUOTE=Robber;25128446]
I had to split the loop in two lines because it always timed out.[/QUOTE]
Grab a copy of Kari Studio or kari_run (the REPL) from the git repo and your life will be so much easier.
[editline]11:19PM[/editline]
Remind me to implement and, or, not and xor in the standard library.
I'll get it done tomorrow.
I'm not quite sure what's happening here... by my logic it should work fine, but you can see the result.
[img]http://localhostr.com/files/e23df3/karistuff3.png[/img]
[QUOTE=turb_;25128667]Can't call a function like that.[/QUOTE]
I'd ask you to make it possible to call anything evaluating to a function like that, but eh, I can't really see any scenario where it'd be necessary.
[QUOTE=esalaka;25128778]I'd ask you to make it possible to call anything evaluating to a function like that, but eh, I can't really see any scenario where it'd be necessary.[/QUOTE]
It would cause problems with passing them to functions as they'd be evaluated immediately if there was anything following them.
Unless you want to put @ before all your functions, it's probably best the way it is.
[QUOTE=turb_;25128809]It would cause problems with passing them to functions as they'd be evaluated immediately if there was anything following them.
Unless you want to put @ before all your functions, it's probably best the way it is.[/QUOTE]
Well, is there a function evaluation operator or something?
[QUOTE=raBBish;25128755]I'm not quite sure what's happening here... by my logic it should work fine, but you can see the result.
[img]http://localhostr.com/files/e23df3/karistuff3.png[/img][/quote]
Tested it myself, it's definitely a bug.
I think it's fixed (as the test passes), but not committed to git.
Does the same issue occur in the debug builds of kari_run? They're usually more 'fresh' than the release builds.
Sorry, you need to Log In to post a reply to this thread.