Functional programming language for Python programmers and friends
Just for you, and this time in the Pythonesque rendering.
module main:
import std (range)
import std.io (printf, IO)
# print the Fahrenheit-Celcius table for fahr = 0, 20, ..., 300
function main(mutable IO io):
Int lower = 0 # lower bound
Int upper = 300 # upper bound
Int step = 20 # step
for Int fahr in range(lower, upper, step):
Double celcius = 5 * (fahr - 32) / 9
std.io.printf(io, "%3d\t%6.1f\n", fahr, celcius)
It does not really look like it, but this language is purely functional. It represents side effects using unique types. If you declare a mutable parameter, you basically declare a unique input parameter and a unique output parameter.
I’m also giving you a list implementation
module std.container.list:
## The standard singly-linked list type
type List[E]:
Nil ## empty list
Node:
E value ## current value
List[E] next ## remaining list
And yes, both languages should be able to be represented using the same abstract syntax tree. The only change is the replacement of the opening curly brace by a colon, the removal of the closing curly bracket and semicolons, the replacement of C-style comments with Python-style comments and the requirement of indentation; oh and the for statement gets a bit lighter as well.
[updated] Functional programming language for C programmers and friends
Just for you:
module main {
import std (range);
import std.io (printf, IO);
/* print the Fahrenheit-Celcius table
for fahr = 0, 20, ..., 300 */
function main(mutable IO io) {
Int lower = 0; // lower bound
Int upper = 300; // upper bound
Int step = 20; // step
for (Int fahr in range(lower, upper, step)) {
Double celcius = 5 * (fahr - 32) / 9;
std.io.printf(io, "%3d\t%6.1f\n", fahr, celcius);
}
}
}
It does not really look like it, but this language is purely functional. It represents side effects using unique types. If you declare a mutable parameter, you basically declare a unique input parameter and a unique output parameter.
I’m also giving you a list implementation
module std.container.list {
/** The standard singly-linked list type */
type List[E] {
Nil; /** empty list */
Node {
E value; /** current value */
List[E] next; /** remaining list */
}
}
}
Thus are only excerpts from a document with tens of pages and the reference implementation of the standard library. The incomplete working draft for the language is attached: JAK Programming Language Early Working Draft (28 pages).
Update: Fixed the link.
hardlink 0.2 RC1 released
I have just released version 0.2 RC1 of my hardlink program. Compared to the 0.1.X series, the program has been rewritten in C, as Python was to memory-hungry for people with millions of files. The new program uses almost the same algorithm and has almost completely the same bugs as the old version.
The code should be portable to all UNIX-like platforms supporting nftw(). I have tested the code on Debian, FreeBSD 9, and Minix 3.2. For storing path names, it uses a flexible array member on C99 compilers, a zero-length-array on GNU compilers, and a array of length 1 on all other compilers (which should work everywhere as far as I heard).
The new version may have slightly different behaviour compared to 0.1.2 when regular expressions are specified on the command-line, as a result of the switch from Python’s regular expression engine to PCRE (if compiled with PCRE support, you can also use POSIX extended regular expressions if you like).
The code is significantly faster than the old code (in situations where it’s not I/O bound), and uses much less memory than the old one. Per file, we now store a <tt>struct stat</tt>, a pointer, an int, a char, and the filename; as well as three pointers for a binary search tree (which uses tsearch()).
It should also be compatible to Red Hat’s original hardlink tool now command-line-wise, there is at least a -c option now. The history and the name conflict are interesting, but probably nothing for this post. We’re even less resistant against changing trees than Fedora’s tool (and derived) currently, but should otherwise be better (and far more complicated and feature-packed). And we don’t require mmap(), but use fread() instead. There was no real performance difference in testing. And we are not GPL-licensed, but use the MIT/Expat license.
The package is currently entering Debian experimental for testing purposes. If you have used hardlink previously, or are just curious, give it try.
And the makefile is now compatible with the various BSD makes out there, if that’s interesting for you.
Link to website:
http://jak-linux.org/projects/hardlink/
Combining ikiwiki and Twitter’s bootstrap
Just because Julien did it, I moved my website to almost the same design now. Still using ikiwiki, of course. I’m still missing a few things, such as marking the currently active page in the menu, but I hope to get that done as well soon. Go to
http://jak-linux.org/
to see it.
Looking for HP Touchpad, Intel tablets, and other devices
If someone in Germany (or want to send it to Germany [at low costs]) still has (new) Touchpads to sell, I’d buy one or two of them at the reduced price (16GB: 99€, 32GB: 129€), or take them for free.
I promise that I will not sell them to others. I’m interested in WebOS, in running Debian and/or Ubuntu on those devices (for the extra fun factor), and lend it to family members for surfing, etc.
I also take other tablets and smart phones and various kinds of ARM and PowerPC hardware (I guess that’s all that’s interesting for me) for free, just send me an email if you have some and want to give them to me. This applies to Intel stuff as well, I’d really like to get some kind of WeTab/ExoPC, but can’t buy one currently (and they’re probably to outdated hardware-wise for buying to make sense).
World, Space, and Licenses
Common licenses for software include the term “worldwide”. Now, what does worldwide mean? The problem with the term worldwide is that it is ambigous and depending on it’s interpretation, violates against DFSG 6 which states: “No Discrimination Against Fields of Endeavor”.
The reason: Space travel. If we take the term worldwide to mean “everywhere on earth”, the license becomes non-free, as it prohibits the use outside of this planet. Affected by this problem are the patent section of GPL-3, the Apache 2.0 license, the CC licenses, the GFDL, and probably also others.
Now what should be used instead? Universal? No, that wouldn’t work in case there are multiple ones (while travelling between them (if they exist) could be impossible, it would still be a restriction). The correct team would probably be “omniversal” meaning “everywhere in the omniverse”. But really, avoiding locations is probably the best way.
In any case, if you have received software from me under a license that uses the term “worldwide”, you can treat worldwide as everywhere, and are thus free to use it outside of earth (and other planets).
