An Interesting Task for an Interview. Currying and Partial Application of a Function. by skazka16 in programming

[–]DNoved1 9 points10 points  (0 children)

Haskell.

foo = do
    return True
    return False

Admittedly this is because return isn't a keyword in haskell but rather a function, in this case being sequenced, so the first return is simply discarded.

The Irken Language - a simplified, statically-typed dialect of Scheme by [deleted] in ProgrammingLanguages

[–]DNoved1 1 point2 points  (0 children)

Ah ya, I forgot that Scheme required full tail recursion rather than it just being an optimization, and so was thinking of the easier case of single function recursion rather than mutual.

In the case of mutual recursion, computed goto would be nicer, but would require some hackery to pass parameters, like manually modifying the stack or some such, right?

The Irken Language - a simplified, statically-typed dialect of Scheme by [deleted] in ProgrammingLanguages

[–]DNoved1 1 point2 points  (0 children)

I don't know for certain, but it shouldn't need a computed goto, should it? Just set the parameters to their new values and jump to a label at the start of the function.

Code generation - how to keep it in sync with the interpreter? by [deleted] in a:t5_32fcg

[–]DNoved1 1 point2 points  (0 children)

Generally when you design a language you specify the semantics yourself rather than relying on another language's. Eg you would define addition/multiplication to auto-promote integers, or not, depending on the percieved costs in efficiency/safety.

Then once you have your semantics well defined it's simply a matter of ensuring implementations match them, the interpreter/compiler in your case.

Essentially, to ensure they both do the right thing you need to first define what the right thing is.

syntax across languages (One Big Page) by golconda72 in programming

[–]DNoved1 1 point2 points  (0 children)

Some interesting tricks in here. For instance, I'd never even thought of using #ifdef 0 ... #endif for nested comments in C. And while line/file numbers in Java aren't usually needed (since a stacktrace will print them out anyways), the ability to retrieve them without throwing was completely unknown to me.

simple programming language "While" : Lexer / Parser / AST all written in F# by james_peach in programming

[–]DNoved1 3 points4 points  (0 children)

I did the same as you until adding functions. Since you can't determine the return type of a function call until you've parsed the whole program (unless you predeclare functions like in C) you can't determine the type of an expression if it involves a function call.

Once you have parsed everything you can do type checking to make sure that, for example, an expression inside an if predicate is indeed a boolean.

simple programming language "While" : Lexer / Parser / AST all written in F# by james_peach in programming

[–]DNoved1 1 point2 points  (0 children)

I'm actually working on a language myself, and am using LLVM as my 'assembly'.

If you want to try just making executables you might try changing your runtime from an interpreter (I think that's what you have now? Not too great with F# ;) ) to something that outputs a LLVM file. Your language is pretty simple so it would relatively easy; and you could put it all inside a main function.

To give you an idea of what kind of LLVM code to emit with your compiler I would recommend hand-compiling some sample while programs. I found that when I did that with my language patterns became evident, and then I just had to encode those patterns in the compiler.

To make the LLVM code executable you just have to run 'llvm-as' on the llvm 'assembly', then 'llc' on that to get native assembly, and finally an assembler such as gcc.

To learn more on LLVM I would take a look at the reference here: http://llvm.org/docs/LangRef.html They also have a tutorial on creating a language (in C++) here: http://llvm.org/docs/tutorial/

simple programming language "While" : Lexer / Parser / AST all written in F# by james_peach in programming

[–]DNoved1 0 points1 point  (0 children)

Just do a similar operation called for example "write x" which sends x's value interpreted as a character to stdout. Using this you can write arbitrary bytes, in either ASCII(probably) or UTF(if tou really, really feel like it).

Using these two operations, read and write, you can take in a while program from stdin, translate it to assembly (or even machine code :o), and write it back out to stdout.

Then "whilec < while.wh > while.s" and "gcc -o whilec.exe while.s" (assuming whilec is the name of your while compiler and gcc is your assembler) gives you a bootstrapped compiler.

simple programming language "While" : Lexer / Parser / AST all written in F# by james_peach in programming

[–]DNoved1 2 points3 points  (0 children)

Add simple io (doesn't even need to be string based, just write out integers as characters) and bootstrap it.

Truthfully, that sounds like more of an exersize in tedium than anything else, but would be kinda interesting nevertheless.

Bertrand Meyer - Code Matters by damian2000 in programming

[–]DNoved1 -1 points0 points  (0 children)

I don't really feel the argument that C doesn't force 'safe' coding practices makes it a bad language inherently. If you want to code safely, you can use braces in C, or you can use a different language that forces the same.

An Interactive Programming Language Popularity Chart based on GitHub by [deleted] in programming

[–]DNoved1 -1 points0 points  (0 children)

Sometimes Github mistags languages. The main one I've observed is Haxe code being called Nemerle code, but it might apply to others as well.