Hacker News new | ask | show | jobs
Tutorial: Zero to Sixty in Racket (prl.ccs.neu.edu)
91 points by Learn2win 3589 days ago
5 comments

I have barely any Racket experience, but this sounds really good to me:

"My favorite part of Racket is how it supports a certain development style of evolving scripts into programs […] I transition from "no code" to "working code" to "robust code" to "re-usable code", the program is almost always runnable."

This is also true of most lisps, and, IME, any language with a good REPL. You can start with snippets which become the bodies of loops and functions, which grow into the full program with (as he points out) various tests and examples constructed along the way.

It's a useful way for approaching a sort of (in my use) hybrid of top-down/bottom-up programming. The things you see on the REPL growing into functions or structs or classes is the bottom-up part, but still with some specification (in this case KWIC indexing) guiding the ultimate interface.

Here is the same project, done in PHP in less then 5 minutes...

  $split_by_whitespace = explode(file_get_contents('exaample.txt')," ");
  $circular = array();
  for ($i=0;$i<count($split_by_whitespace);$i++) {
	  array_push(array_shift($split_by_whitespace));
	  $circular[]=$split_by_whitespace;	  
  }
  sort($circular);
  print_f($circular);
While I am sure there a lot of interesting use cases for Racket, but when it comes to processing array data, I'll take PHP everytime.
1) Cool.

2) This isn't, strictly, about processing text data but about an approach to development that Racket makes easy.

Specifically:

  Prototype in a REPL or similar
  Easily integrate unit tests alongside the relevant
    units.
  Convert it to a statically typed implementation:
    Remove some need for run-time checks
    Depending on programming ethos has significant value
3) If you really want to do text processing, let's go with perl:

  print sort map{sub{map{push@_,shift;"@_\n"}@_}->(split)}<>
From: http://www.perlmonks.org/?node_id=62671

4) Things missing from yours and the perl one:

  Usage notes
  Command line flags/options
  Tests
  Static typing (maybe of value for small programs like
    this, but useful in larger programs [EDIT:0])
The first three are trivially added to the other two programs (though the perl one will need some reformatting). But the fourth is impossible. Again, for this scope of project (a demonstration, mind you) the tests and static typing aren't as essential. But if you want this code to live on, and potentially become part of a library of more utilities, they're very helpful.

[0] and projects that depend on this is a library call so they know the types of the arguments and returns.

This non working prototype code is bothering me....fixed.

<?php

# considering t2.txt contains below two lines

#a c d f n z r

#granc dr ssdo and

#

$file_lines = file_get_contents('./t2.txt');

$split_by_line = explode("\n",$file_lines);

$circular = array();

foreach ($split_by_line as $line) {

        $split_by_words = explode(' ',$line);
        sort($split_by_words);

        $circular = $split_by_words; 
        foreach($split_by_words as $word){
                array_push($circular,array_shift($circular));

                echo implode($circular," ") . "\n"; 

        }

        $split_by_words = null;

        echo "\n";

}
Prefix your code with two spaces on each line and HN will include it verbatim. Otherwise it thinks you have paragraphs with line breaks that it ignores.
I really like Racket, but I wish there was more community and support around it outside the educational world.
Great to see Northeastern's computer science program represented on Hacker News
Does he use the symbol for lambda without saying how to type it or whether there's an ascii equivalent like "lambda"?
you just type the text "lambda". some editors (emacs, drracket) can automatically convert it to lambda the symbol.