Giter VIP home page Giter VIP logo

Comments (4)

Hacker-007 avatar Hacker-007 commented on June 14, 2024

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.

thenickcox avatar thenickcox commented on June 14, 2024

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.

Hacker-007 avatar Hacker-007 commented on June 14, 2024

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.

thenickcox avatar thenickcox commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.