• What Are You Working On? April 2015
    1,741 replies, posted
[QUOTE=Berkin;47455045]On a whim, I decided to have another go at that expression parser for Rant's scripting layer. I used iterators to create a stack of resumable functions that handle the parsing, which effectively eliminates all native recursion in the interpreter. [img]http://i.imgur.com/3GcSRb9.png[/img] [I]And it fucking worked.[/I][/QUOTE] A stack of resumable functions. If that doesn't sound like recursion then I don't know what does.
[QUOTE=Darwin226;47455066]A stack of resumable functions. If that doesn't sound like recursion then I don't know what does.[/QUOTE] It's an explicit stack. The point of it is to eliminate the possibility of a StackOverflowException happening due to an infinitely recursive pattern. Rant itself works the same way, halting execution after the call stack exceeds 64 levels.
[QUOTE=Berkin;47455069]It's an explicit stack. The point of it is to eliminate the possibility of a StackOverflowException happening due to an infinitely recursive pattern. Rant itself works the same way, halting execution after the call stack exceeds 64 levels.[/QUOTE] I see. That makes sense.
Having fun with strings now. [img]http://i.imgur.com/MIrOjXb.png[/img]
[QUOTE=Berkin;47455120]Having fun with strings now. [IMG]http://i.imgur.com/MIrOjXb.png[/IMG][/QUOTE] Is Rant Turing complete?
Been a while since I worked on my gardening game since I've been busy with university. I implemented a few more things and then decided to start trying to add in plant maintenance so you have to keep them watered and fertilised otherwise they will decay. When testing out different ways of getting them to visibly decay I did this: [vid]http://s1.webmshare.com/o8NKv.webm[/vid] Might include a secret rainbow plant in the game.
[QUOTE=Darwin226;47455268]Is Rant Turing complete?[/QUOTE] The dev branch isn't at the moment, but the old variable system combined with the [cmp] function is probably enough to make it Turing-complete.
Trying to learn Rust. Hating it so far.
[QUOTE=Berkin;47455315]The dev branch isn't at the moment, but the old variable system combined with the [cmp] function is probably enough to make it Turing-complete.[/QUOTE] Is there no way then to have some static analysis determine if the program causes a stack overflow? [editline]4th April 2015[/editline] [QUOTE=Simspelaaja;47455497]Trying to learn Rust. Hating it so far.[/QUOTE] What are you hating? I don't know Rust but it seemed relatively nice when I was skimming through the docs. Except the 4 different kinds of pointers, but that probably isn't an issue really.
Rust is a lot better if you appreciate the safety, otherwise you are just fighting it.
I've just learnt about [URL="http://www.falconpl.org"]Falcon[/URL]. [code] #!/usr/bin/falcon > "Hello, FP!" object Ew description = "It's some kind of lua and python hybrid" function desc ( ) return self.description end function setdesc ( desc ) self.description = desc end end > Ew.desc() Ew.setdesc("It's weird.") > Ew.desc() [/code] -> [code] eyes@judgment ~/falconprog> falcon test.fal Hello, FP! It's some kind of lua and python hybrid It's weird. [/code]
[QUOTE=reevezy67;47454717]Now expand them all.[/QUOTE] Slightly less clean. :D [t]http://imgur.com/g3xrwLv.png[/t] Also, interestingly, I'm running Windows 10 TP 10049. The build notes claim that the XAML designer crashes, making VS 2015 unusable on this build to the point where they recommend developers don't update, but it runs just fine for me :/
I taught myself Ruby yesterday and today I wanted to reinforce what I had learned, so I wrote a simple IRC bot. Can anyone who uses Ruby have a look over my code and point out any style problems (going by general opinion) or things I could have done in a more idiomatic way? Thanks! [url]https://gist.github.com/BackwardSpy/eeceeedf0f79ab5a3894[/url] I'm enjoying the language so far, it seems very readable and quick to write.
[QUOTE=reevezy67;47455670]Rust is a lot better if you appreciate the safety, otherwise you are just fighting it.[/QUOTE] Rust's type system is pretty amazing to use as well
[QUOTE=Darwin226;47455560] What are you hating? I don't know Rust but it seemed relatively nice when I was skimming through the docs. Except the 4 different kinds of pointers, but that probably isn't an issue really.[/QUOTE] A few things: 1. The standard library is not very well documented. The official API doc has very few examples, at least compared to MSDN, MDN and ClojureDocs. There is an ebook called [URL="http://rustbyexample.com/"]Rust by Example[/URL], which covers most language features (briefly), but it doesn't cover the standard library very well. 2. What makes #1 a lot worse is that before 1.0 beta, Rust's standard library and syntax have been very unstable. There have been major changes every few weeks, and most unmainted Rust code (such as Stack Overflow answers) older than a few months won't compile. A lot of features have been removed entirely, such as compiler enforced pure functions, string indexing with square[brackets], the garbage collector (Gc<T>), struct inheritance, reflection support and even the entire runtime. 3. There are many string types: String, &str and std::ffi::CStr. While I'm sure there is a valid reason for their existence, they're confusing for a beginner. I think String is a Vec<u8> with some extra goodies, &str is just an alias for &[u8], and CStr is a pointer to a null-terminated string, but I'm not sure. The string type implements [url="http://doc.rust-lang.org/core/str/trait.StrExt.html#tymethod.contains"]a trait[/url] that contains many important string-related functions, but as of 1.0 beta the module is unstable, which means you can't use it outside of nightly builds, so you have to use workarounds for string manipulation. A string can be cast into a slice with .as_slice(), but according to the compiler and the docs it has been deprecated. I don't know. 4. The compiler throws a warning every time you call a function without using the result (e.g every time you write into stdout). Why? This is not supposed to be Haskell. 5. I like pattern matching and the safety offered by Option<T, E> & friends, but I'm not a fan of the fact that you are forced to use them all the time. 6. No support for virtual methods, abstract structs, struct inheritance, polymorphism, default arguments or variadic functions (as far as I know). Not a dealbreaker, but I'd prefer to have them.
[QUOTE=Simspelaaja;47456046]-stuff-[/QUOTE] 3. String is a Vec<u8> with a guarantee that the contents are valid UTF-8, &str is an &[u8] with the same guarantee. CStr is a good 'ol C-string and is only useful for C FFI. There's also OsStr which is necessary because the OS can return hilariously broken unicode. as_slice() was deprecated in favor of the more generic AsRef (as_ref) trait. 4. Only functions that are no-ops without using the result or functions that return errors you should always handle 5. What would the alternative be? 6. Box<Trait> and &Trait allow for something like virtual methods. Associated types and constants allow you do everything abstract data types can do. Not sure what you mean by lacking polymorphism, since that's bread and butter for most Rust code.
[QUOTE=Tobba;47456090]-words-[/QUOTE] 3. Thanks for the clarification. 4. I get the idea, but what if I don't want to handle stdout.write? 5. I don't really know. 6. Thanks for the clarification again. I must have read something old/misleading. Not very uncommon with Rust. :v:
[QUOTE=Simspelaaja;47456157] 4. I get the idea, but what if I don't want to handle stdout.write?[/QUOTE] Haskell handles those cases by providing a version of the same function that doesn't return anything. That way you can explicitly convince the compiler that you don't want to handle output without having verbose code (the function usually just has a _ after it's name). I guess you could just make that kind of a wrapper around write. Though it would be best to see if that's at all idiomatic.
Right now I am studying physics and I got it - the system how buoyancy works :v:. It's pretty simple actually. [editline]4th April 2015[/editline] Oh, and with 4D dimensional space you can easily make portals/tunnels in 3D space. So it is possible to make 3D engine that works inside 4D space and you have portals for free :V:. Actually it's not portal, it's just tunnel that exists in another layer of reality, through which you can walk.
I more or less finished the parser for my language but I decided that I want play around with it some more and make tests for it. One of the ways you can test a parser is use QuickCheck to make arbitrary ASTs, then pretty print them into source code, then parse them and them compare the original AST with the new one. The fun part is in the middle of the process where you have enough facilities written to generate random programs in your language. The names were too ugly when they were randomly generated so I've fixed them to names of fruits. Here's a sample result: [code]import AppleBanana as PearPear apple :: (TangerineOrange -> (Orange.BananaApplePear ((PearPear -> var)) (TangerinePineappleGrape.LemonOrangeBanana (x) (OrangeBananaTangerine) (PineappleTangerinePear.ApplePineapplePineapple)) -> ())) apple orangeLemonApple pineapplePineappleBanana -> LemonPineapple.orangeLemonGrape grapeAppleOrange :: ((() -> Grape.Tangerine.TangerineOrangeTangerine) -> ()) grapeAppleOrange tangerineAppleLemon -> for bananaPineappleLemon from 8.926305171580932 to -2 for lemonLemonBanana from 3 to -3 0 (OrangeGrapeBanana) tangerine = -3.2272732472304484 var lemonBanana = 0 lemonTangerine :: (ApplePearBanana (w) -> Pear.GrapeGrape) lemonTangerine pear -> 0 for applePearOrange from ";\197" to 1 for banana from Pear.PearPearBanana.apple to 1 var orangeGrape = BananaPear.Orange.LemonOrangeOrange.grapeTangerine "X4" (a) pineapple = Pear.AppleBananaTangerine.bananaLemonBanana return "|Q"[/code] [editline]4th April 2015[/editline] Here's what the generator for random ASTs looks like [url]https://gist.github.com/LukaHorvat/4cab7cdfd7e2124639e7[/url]
[QUOTE=Darwin226;47456483]I more or less finished the parser for my language but I decided that I want play around with it some more and make tests for it. One of the ways you can test a parser is use QuickCheck to make arbitrary ASTs, then pretty print them into source code, then parse them and them compare the original AST with the new one. The fun part is in the middle of the process where you have enough facilities written to generate random programs in your language. The names were too ugly when they were randomly generated so I've fixed them to names of fruits. Here's a sample result: [code]import AppleBanana as PearPear apple :: (TangerineOrange -> (Orange.BananaApplePear ((PearPear -> var)) (TangerinePineappleGrape.LemonOrangeBanana (x) (OrangeBananaTangerine) (PineappleTangerinePear.ApplePineapplePineapple)) -> ())) apple orangeLemonApple pineapplePineappleBanana -> LemonPineapple.orangeLemonGrape grapeAppleOrange :: ((() -> Grape.Tangerine.TangerineOrangeTangerine) -> ()) grapeAppleOrange tangerineAppleLemon -> for bananaPineappleLemon from 8.926305171580932 to -2 for lemonLemonBanana from 3 to -3 0 (OrangeGrapeBanana) tangerine = -3.2272732472304484 var lemonBanana = 0 lemonTangerine :: (ApplePearBanana (w) -> Pear.GrapeGrape) lemonTangerine pear -> 0 for applePearOrange from ";\197" to 1 for banana from Pear.PearPearBanana.apple to 1 var orangeGrape = BananaPear.Orange.LemonOrangeOrange.grapeTangerine "X4" (a) pineapple = Pear.AppleBananaTangerine.bananaLemonBanana return "|Q"[/code] [editline]4th April 2015[/editline] Here's what the generator for random ASTs looks like [url]https://gist.github.com/LukaHorvat/4cab7cdfd7e2124639e7[/url][/QUOTE] You are bananas! But I see, essentially you generate original AST from which you make string (source code), then parse this string back into AST, and compare the ASTs? Makes sense, but that is quite insanely hard, isn't it?
I have to write a 1D cellular automata for school which is real simple but we need to parallelize it so it performs better on a multicore machine. Except I need to use a Java library written by one of the professors instead of just doing the threads myself and the only method it gives us is parallelFor(). So no thread pools, no joining threads, no synchronized blocks. I can't parallelize each generation for obvious reasons but running the cell calculations in separate threads each generation is too much overhead to be better (its actually ~10x slower than just sequential calculation). [CODE]for(int step = 1; step <= steps; step++){ int[] next = new int[cells.length]; parallelFor(0, cells.length - 1).exec(new Loop(){ public void run (int cell){ int nextIndex = (cell + 1) % cells.length; int prevIndex = (cell == 0) ? cells.length - 1: cell - 1; byte v = 0; v |= cells[prevIndex] << 2; v |= cells[cell] << 1; v |= cells[nextIndex]; next[cell] = Character.digit(updateRule[v], 10); } }); System.arraycopy(next, 0, cells, 0, cells.length); int count = popCount(cells); if(count < smallest[1]) {smallest[0] = step; smallest[1] = count;} if(count > largest[1]) {largest[0] = step; largest[1] = count;} }}[/CODE] There's no mention of how shared resource access works with this library but theres no issues with concurrent modification of next[] or access of cells[]. I wonder if duplicating the data would save more time in data access than it wastes in setting it up. Anyway, I'm just frustrated with this assignment, carry on.
I've started learning [URL="https://golang.org/"]Go[/URL] and it works! Also, there're lots of really good tutorials/books which is always really useful.
Added a [URL="https://github.com/Sidneys1/BatchImageProcessor#cli"]CLI to Batch Image Processor[/URL] :D Only took all day :)
[QUOTE=TheEyes;47455812]I've just learnt about [URL="http://www.falconpl.org"]Falcon[/URL]. [code] #!/usr/bin/falcon > "Hello, FP!" object Ew description = "It's some kind of lua and python hybrid" function desc ( ) return self.description end function setdesc ( desc ) self.description = desc end end > Ew.desc() Ew.setdesc("It's weird.") > Ew.desc() [/code] -> [code] eyes@judgment ~/falconprog> falcon test.fal Hello, FP! It's some kind of lua and python hybrid It's weird. [/code][/QUOTE] I use Lua because it's not Python. WHO WOULD COMBINE THE TWO!!?1/1 this is the language of the cthulu summoning spell
Cleaned up the parentheses in the output a bit and eliminated some badly formed expressions. [code]import Orange.AppleOrange as GrapePear data AppleBanana t = TangerineGrape ((Lemon) -> Tangerine.TangerineLemon -> ()) (PearPineapple BananaApple -> m) b record Tangerine = tangerine :: Tangerine Lemon.Tangerine grapePear :: Lemon.Grape.Banana Pear pear :: BananaGrape.Pineapple.Grape -> PearPear.Pear.BananaTangerine -> () data Apple k z = Orange | Orange | Grape | Apple Lemon BananaApple bananaGrape :: TangerineOrange.TangerineGrape.GrapeApple -> TangerineTangerine.PearPineapple bananaGrape pineapple -> return AppleApple.Banana.Lemon "\193_" 20.766826955629302 Lemon.LemonPear.PearTangerine tangerineTangerine :: GrapeOrange -> () tangerineTangerine pearApple -> if 12.433432530290641 then return BananaTangerine else "" for appleApple from "5\224" to Orange.Pear | 2 for lemon from "#d" to "" | 1 if "3T" then if "\222]L" then return "a\239" 3 Tangerine.Apple.TangerineTangerine.banana GrapeOrange.PineappleApple.Apple orange = 2.899137980060688 else for tangerine from 1.5023569537438786 to "" | 3 PearPineapple.Apple for pear from "\SI\ETB" to 1 (z -> ()) tangerineApple = Tangerine.Lemon.LemonApple 7.6835195639875895 if 3 then m orangeLemon = "\ACK" else var tangerinePear = 3 var lemon = "" if GrapeLemon.Lemon.pineapple then for lemon from Tangerine.OrangeLemon to 1 for orangeGrape from 3 to 3 return 2.94236487164694 else "!\226" for grapeOrange from Grape to 1 if "/" then for lemonTangerine from 4.463175855399267 to 2 return 3 var grapeBanana = 1 return PearTangerine.Pear.Apple.bananaLemon 2[/code]
[QUOTE=Darwin226;47457742]Cleaned up the parentheses in the output a bit and eliminated some badly formed expressions. [code]import Orange.AppleOrange as GrapePear data AppleBanana t = TangerineGrape ((Lemon) -> Tangerine.TangerineLemon -> ()) (PearPineapple BananaApple -> m) b record Tangerine = tangerine :: Tangerine Lemon.Tangerine grapePear :: Lemon.Grape.Banana Pear pear :: BananaGrape.Pineapple.Grape -> PearPear.Pear.BananaTangerine -> () data Apple k z = Orange | Orange | Grape | Apple Lemon BananaApple bananaGrape :: TangerineOrange.TangerineGrape.GrapeApple -> TangerineTangerine.PearPineapple bananaGrape pineapple -> return AppleApple.Banana.Lemon "\193_" 20.766826955629302 Lemon.LemonPear.PearTangerine tangerineTangerine :: GrapeOrange -> () tangerineTangerine pearApple -> if 12.433432530290641 then return BananaTangerine else "" for appleApple from "5\224" to Orange.Pear | 2 for lemon from "#d" to "" | 1 if "3T" then if "\222]L" then return "a\239" 3 Tangerine.Apple.TangerineTangerine.banana GrapeOrange.PineappleApple.Apple orange = 2.899137980060688 else for tangerine from 1.5023569537438786 to "" | 3 PearPineapple.Apple for pear from "\SI\ETB" to 1 (z -> ()) tangerineApple = Tangerine.Lemon.LemonApple 7.6835195639875895 if 3 then m orangeLemon = "\ACK" else var tangerinePear = 3 var lemon = "" if GrapeLemon.Lemon.pineapple then for lemon from Tangerine.OrangeLemon to 1 for orangeGrape from 3 to 3 return 2.94236487164694 else "!\226" for grapeOrange from Grape to 1 if "/" then for lemonTangerine from 4.463175855399267 to 2 return 3 var grapeBanana = 1 return PearTangerine.Pear.Apple.bananaLemon 2[/code][/QUOTE] Does it return a fruit salad?
[QUOTE=Darwin226;47457742][CODE]for tangerine from 1.5023569537438786 to "" | 3[/code][/QUOTE] What's going on here?
[QUOTE=Dr Magnusson;47457879]What's going on here?[/QUOTE] Obviously it's integral from 1.5023.. to "" of function f(x) = 3
[QUOTE=Dr Magnusson;47457879]What's going on here?[/QUOTE] Obviously a loop from 1.502 to the very essence of nothingness or 3. The language is very philosophical.
Sorry, you need to Log In to post a reply to this thread.