Live data from Hacker News

Felix - a fast scripting language

felix-lang.org

61–70 of 88 posts

Re: Felix - a fast scripting language

#61
post #46

Earlier quoted context omitted.

My "good enough" definition: a scripting language is a language that does not require you to write a main() function or define a class / object in order to produce output and features automatic memory management.

So Common Lisp and Fortran are scripting languages? This test seems to be more like "Is the language heavily influenced by C or C++?"

Then add it's easy to create one-liners.

Re: Felix - a fast scripting language

#62
post #42

The web page rubs me the wrong way. How can you claim to be the fastest anything without a single benchmark? How can you claim to be a "scripting language" when you're statically-typed and compile to C++? What does "scripting language" even mean then? How can you say things like "it will be a bit slow the first time but subsequent runs will load much faster than any VM." Any VM? Are you really "much faster" than: $ t…

are you referring to the "The fastest scripting language on Earth" tagline? i saw that as a way to say "look, this is a compiled language that you can use as a scripting language" with a touch of whimsical humour.

Did I mention Felix is based on Cat-e-gory theory and named for the inventor of one-sided donuts?

Re: Felix - a fast scripting language

#63

Earlier quoted context omitted.

How is int*int*int*int*int or even int^5 better than a plain int[5]? To me, the use of mathematical operators * and ^ causes dissonance.

If you're coming from a type theory background (which, granted, few are), this operator is actually perfectly natural. http://en.wikipedia.org/wiki/Product_type

I don't come from much of a type theory background. I certainly have no formal education in the field. I just know how a Cartesian product works, and that's enough to make me get it.

Re: Felix - a fast scripting language

#64

I find it definitely a nice language proposal, but there are a few issues, I guess. A first one is that many of the distinctions introduced (such as proc,fun,gen) are all optimization issues. I would appreciate if it were possible to do that long after you're done with just making the program work. The language may force the developer way too early in the process to think of things that do not matter at that point. I…

The proc/gen/fun distinction isn't entirely an optimisation issue, its a semantic one, heavily related to the implementation model. In principle fun and gen use the machine stack for return addresses whilst proc uses a heap allocated list which allows cooperative multi-tasking using channels for communication: such so-called spaghetti stacks are easy to swap. Machine stacks can only be swapped in a conforming way in C/C++ by using pre-emptive threads which is precisely what we're trying to avoid.

I said "entirely" above because semantics and optimisation are heavily intertwined in any system.

The comment about "syntactic sugar" is valid: there are at least four operators with different precedences all meaning "application of function to arguments". However note that in most languages this is true anyhow: x + y is really just add (x,y). Finding a good set of squiggles and marks that's acceptable to many people isn't easy.

However the syntax is defined in the library, in user space, so you can add your own grammar or design your own domain specific sub-language, and add your favorite squiggles that way. Any contributions to making the standard syntax simpler would be welcome: I'm constantly struggling with this issue because I'm well aware syntax matters, especially early in learning a language.

Re: Felix - a fast scripting language

#65

Earlier quoted context omitted.

If you're coming from a type theory background (which, granted, few are), this operator is actually perfectly natural. http://en.wikipedia.org/wiki/Product_type

Aren't product types just tuples, whereas arrays correspond to list types? The '^' operator can only construct arrays whose elements are of a single type, right?

That's correct. However, somewhat problematically, Felix considers the tuple int * int to actually be an array int ^ 2. It's not entirely clear this "automatically applied isomorphism" is a good idea though. However it means arrays "drop out" of the notion of a tuple as a special case.

Internally such arrays have a special representation which allows arrays of 100,000 values, something which could never be represented by a tuple type (and still get reasonable compile times :)

Re: Felix - a fast scripting language

#66
post #64

I find it definitely a nice language proposal, but there are a few issues, I guess. A first one is that many of the distinctions introduced (such as proc,fun,gen) are all optimization issues. I would appreciate if it were possible to do that long after you're done with just making the program work. The language may force the developer way too early in the process to think of things that do not matter at that point. I…

The proc/gen/fun distinction isn't entirely an optimisation issue, its a semantic one, heavily related to the implementation model. In principle fun and gen use the machine stack for return addresses whilst proc uses a heap allocated list which allows cooperative multi-tasking using channels for communication: such so-called spaghetti stacks are easy to swap. Machine stacks can only be swapped in a conforming way in…

I have created a blog post explaining why I think the language has too many problems to ever take off: http://erik-poupaert.blogspot.com/2013/01/the-felix-programm...

Re: Felix - a fast scripting language

#67
post #8

Earlier quoted context omitted.

The webserver, which is written in Felix, translates a particular format called "fdoc" to create the tutorial and slides, including embedded colourised hyperlinked Felix and C++ code. The translation is to a mix of HTML5 and Javascript. This link shows the source of the first slideshow: http://felix-lang.org/web/slides/language-overview.fdoc?text All the documentation and layout needs a lot more work. [BTW: I'm the p…

Yttrill, I see that Felix is 12+ years old. I remember reading about Felix on Lambda the Ultimate a few years ago. :) Over those 12 years, what are some of the biggest changes (in the language or its implementation) you have made? Where the changes mostly evolutionary? https://github.com/felix-lang/felix/commits/master?page=135

This is a hard question to answer. In general the emphasis changed from getting the compiler to work, and to generate efficient code, to using the technology to implement a rich set of libraries (feedback into compiler), and then writing some simple tools (feedback into libraries and compiler).

Probably the single biggest feature was the introduction of Haskell style type classes as a way to systematically provide "generic" features like comparisons and conversions to string which are de rigueur in dynamically typed scripting languages.

Less obvious but quite important was switching the parser from Ocamlyacc to Dypgen combined with OCScheme, which together put the grammar in user space, allowing almost the entire grammar to be put in the library. A lot of new features were added with very little or no change to the compiler by just adding some EBNF grammar and suitable Scheme action code to the parser.

This can be very effective. For example, with only one extra term in the compiler, I added a dynamic object system that looks a lot like Java with objects and interfaces including "implements" and "extends" stuff. It just uses records of closures (the compiler mod added record extension), but the syntax is neat and almost immediately I used it to factor the webserver into separately compiled plugins. I originally implemented this as a kind of joke, to show off the expressive power in respect of Domain Specific Sub-Languages, but not intended for use. The joke was on me :)

Re: Felix - a fast scripting language

#68
post #21

Why do language designers continue to insist on semi-colon terminated lines?

It's simpler to parse and some programmers prefer them.

And simpler to parse has another benefit Given an effort X spent writing the parser, users of the language get better error messages

Also, I do not think of those semicolons as noise They make text easier to parse for humans, too That's why you see most people end sentences, paragraphs and HN posts with a 'superfluous' period

EDIT: Some people will find the above quite readable I am somewhat in that camp Problem is, however, that in English and other languages capitals like I and E are not guaranteed to be sentence starters That muddles the waters considerably Many programming languages have worse problems.

Re: Felix - a fast scripting language

#69
post #20

Which high level optimisations are we talking about?

As a whole program analyser, Felix does a lot of optimisations. The most important one is inlining. Felix pretty much inlines everything :)

When a function is inlined, there are two things you can do with the arguments: assign them to variables representing the parameters (eager evaluation) or just replace the parameters in the code with the arguments (lazy evaluation).

Substitution doesn't just apply to functions: a sequence of straight line code with assignments can be converted into an expression by replacing occurrences of the variables with the initialising expressions.

For a small number of uses, substitution is the usually the most efficient. For many uses, lifting the common expressions to a variable is more efficient. If we're dealing with a function (in C++ the model is a class) for which a closure is formed (in C++ the model is an object of the class) lazy evaluation is very expensive because the argument itself must be wrapped in an object to delay evaluation.

By default, Felix val's and function arguments use indeterminate evaluation semantics, meaning the compiler gets to choose the strategy. This leads to high performance, but it also means we need a way to enforce a particular strategy: for example vars and var parameters always trigger eager evaluation. This leads to some complication in the language.

Felix also does other optimisations, for example it does the usual self-tail call optimisation. This one works best if you do inlining at the right point to convert a non-self tail call (which cannot be represented for functions in C) into a self-tail call (which is replaced by a goto).

Felix also does parallel assignment optimisation.

It ensures type-classes have zero cost (unlike Haskell which, by supporting separate compilation, may have to pass dictionaries around).

There is quite a lot more: eliminating useless variables, functions, unused arguments, etc. There are even user specified optimisations based on semantics, such as

  reduce idem[T]  (x:list[T]) : list[T] = x.rev.rev => x;
which says reversing a list twice leaves the original list, so just get rid of these two calls.

Actually one important aspect to the optimisation process: by default a function is a C++ class with an apply() method. This allows forming a closure (object). The object is usually allocated on the heap. However Felix "knows" when it can get away with allocating such an object on the machine stack instead (saving a malloc and garbage collection). Furthermore, Felix "knows" when it can get away with a plain old C function, and generates one of those instead if it can. And all of that occurs only if the function wasn't entirely eliminated by inlining all the calls.

So although you should think of Felix functions and procedures as objects of C++ classes allocated on the heap and garbage collected, any significant program implemented with this model without optimisations would just drop dead.

Re: Felix - a fast scripting language

#70
post #67

Earlier quoted context omitted.

Yttrill, I see that Felix is 12+ years old. I remember reading about Felix on Lambda the Ultimate a few years ago. :) Over those 12 years, what are some of the biggest changes (in the language or its implementation) you have made? Where the changes mostly evolutionary? https://github.com/felix-lang/felix/commits/master?page=135

This is a hard question to answer. In general the emphasis changed from getting the compiler to work, and to generate efficient code, to using the technology to implement a rich set of libraries (feedback into compiler), and then writing some simple tools (feedback into libraries and compiler). Probably the single biggest feature was the introduction of Haskell style type classes as a way to systematically provide "g…

Thanks for the background. Moving the grammar into "user space" from the compiler is a particularly interesting feature!
Post reply on HN