Comments (5)
Since koan has the idea of real first-class anonymous functions, you don't have to introduce Ruby-style blocks. Simply make your loop expression like this:
'8:' RANGEEXPR FUNCTIONEXPR
The advantage of this is that you can use an existing function, say f, and then write something like:
8: 0..100 f
which says run f for each value in 0..100. You would check at compile time that f indeed had ONE parameter of numeric (or integer) type.
You can also use anonymous functions here:
8: 0..100 (x -> p x)
to print 0 through 100.
TL;DR Ditch the Rubyism. Ya don't need it. Ya gots functions.
from koan-lang.
sounds good to me
from koan-lang.
Just remember that in the previous comment FUNCTIONEXPR may or may not be a real syntactic category in your final design. If you allow variables for functions (as in the example I gave) then you aren't able to distinguish functions from non-functions there. That will be a runtime check. To avoid the runtime check, you'd have to require that the expression in that position be an anonymous function (or something like that -- something that you can tell at compile time would be a function). I'm not saying the runitme check is necessarily bad; I'm just pointing out a tradeoff.
from koan-lang.
To resolve this issue, as advised by Dr. Toal, we're going to remove the blocks and replace them with anonymous functions that have an alternative syntax.
Generally, anonymous functions take parameters that are denoted by underscores, but we are going to allow an alternative syntax that (as I understand from the conversation I had with Dr. Toal) works with for-loops and while loops.
8: 1..100 i { p: x } c: New syntax, in which the ruby-style block is no
c: longer a ruby-style block, but an anonymous function.
c: Thus, blocks no longer exist in our language.
8: { p: "loop forever" } c: While-loops will work the same way, with anonymous
c: functions instead of blocks, but this anonymous function
c: won't take any arguments. And since while-loops take
c: break statements to jump out of the loop, I don't think this
c: will cause any problems.
The reason for doing this is that there is no reason to have both blocks and anonymous functions at the same time. Blocks are ruby's way of getting around the fact that it doesn't have anonymous functions, and since our language support anon-funcs, there's no reason why we can't use them where we were going to use blocks. We shouldn't have both because the two options would be competing syntaxes, and as Dr. Toal said, there's no reason to have that either.
from koan-lang.
Also, we're ditching absolute value signs.
from koan-lang.
Related Issues (17)
- Design syntax for object-orientation
- Make project Maven-buildable
- Abstract syntax-tree
- Return Statement HOT 1
- Print Statement Syntax HOT 1
- notes! HOT 2
- Choice conflict in For Loop HOT 1
- left-hand-side subscripted variable references in assignments not parsing correctly
- Return statement or expression statements HOT 1
- Notes From Dr. Toal's Review HOT 3
- We Need Sample Code
- Static Types HOT 5
- Fix syntax-checker HOT 4
- Static Typing and Return Types HOT 2
- Objects vs. Hashes HOT 7
- Use Lookaheads to fix warnings in SyntaxChecker HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from koan-lang.