Comments (4)
The thing about the language is that the program consists of functions, so the code samples do not start with a function. If the code was wrapped in a function, the code would work. I could also create a "ghost function" to wrap the code in, but this would not work if the code defines its own functions.
from envious.
Okay, that makes total sense. But now if I try to wrap it in a function like main
and begin it with define
, I get expected prefix expression
. What's an example of a hello world that will compile and run here?
I tried
define main() :: Int = // I know this doesn't return an Int, but you said you didn't have void implemented, so ¯\_(ツ)_/¯
define add(x: Int, y: Int) :: Int = x + y
print(add(2,3))
And got that it expected a prefix.
Maybe I just haven't had enough coffee.
from envious.
The first comment is that the types of the function do not add up. As a function, print
is not defined yet so that would also not work. Next, the function print
returns a Void
type. So, the main function should return Void
(I believe Void as a type is implemented). The actual error that you are referencing has to do with the parser. The parser looks to the right of the main function and realizes that there is a single expression. The body provided, however, is a define expression or a new function. This is currently not implemented because it requires closures to be implemented, which once again goes back to a GC.
The code sample below should work:
extern print(Int) :: Void // Define an external print function that takes an Int and returns nothing. This will have to be linked later.
define add(x: Int, y: Int) :: Int = x + y // Define the add function
define main() :: Void = print(add(2, 3)) // Create the main function that returns no value whose body is the result of calling the print function.
from envious.
Yep! I can confirm that compiles now. So I'll be extra excited when the TUI shows the output rather than the compiled code, which I know is non-trivial and I know you're working on.
from envious.
Related Issues (13)
- Add a basic REPL HOT 2
- REPL not interacting as expected HOT 2
- Add a ParenthesizedExpression
- Better semantic analysis HOT 1
- Implement return statements HOT 1
- Garbage Collector HOT 3
- Explanation of currently supported types? HOT 2
- Quick start guide? HOT 2
- Return types are not inferred for functions
- Add code generation for function calls
- Add option in CLI to generate well formatted Dark code
- Rethink CLI architecture 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 envious.