mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
more and better samples for Nu, Racket, Scala
- 99 bottles of beer is more substantial than hello world - also fixed chmod 755 on several .script! files
This commit is contained in:
0
samples/JavaScript/js2.script!
Normal file → Executable file
0
samples/JavaScript/js2.script!
Normal file → Executable file
27
samples/Nu/RandomApp.nu
Normal file
27
samples/Nu/RandomApp.nu
Normal file
@@ -0,0 +1,27 @@
|
||||
;; main.nu
|
||||
;; Entry point for a Nu program.
|
||||
;;
|
||||
;; Copyright (c) 2007 Tim Burks, Neon Design Technology, Inc.
|
||||
|
||||
(load "Nu:nu") ;; basics
|
||||
(load "Nu:cocoa") ;; cocoa definitions
|
||||
(load "Nu:menu") ;; menu generation
|
||||
(load "randomapp") ;; Aaron Hillegass' famous example
|
||||
|
||||
;; define the application delegate class
|
||||
(class ApplicationDelegate is NSObject
|
||||
(imethod (void) applicationDidFinishLaunching: (id) sender is
|
||||
(build-menu default-application-menu "RandomApp")
|
||||
(set $random ((RandomAppWindowController alloc) init))))
|
||||
|
||||
;; install the delegate and keep a reference to it since
|
||||
;; the application won't retain it.
|
||||
((NSApplication sharedApplication) setDelegate:
|
||||
(set delegate ((ApplicationDelegate alloc) init)))
|
||||
|
||||
;; this makes the application window take focus when
|
||||
;; we've started it from the terminal
|
||||
((NSApplication sharedApplication) activateIgnoringOtherApps:YES)
|
||||
|
||||
;; run the main Cocoa event loop
|
||||
(NSApplicationMain 0 nil)
|
||||
0
samples/PHP/php-script.script!
Normal file → Executable file
0
samples/PHP/php-script.script!
Normal file → Executable file
0
samples/PHP/php.script!
Normal file → Executable file
0
samples/PHP/php.script!
Normal file → Executable file
17
samples/Racket/99-bottles-of-beer.scrbl
Normal file
17
samples/Racket/99-bottles-of-beer.scrbl
Normal file
@@ -0,0 +1,17 @@
|
||||
; Clean, simple and efficient code -- that's the power of Racket!
|
||||
; http://racket-lang.org/
|
||||
|
||||
(define (bottles n more)
|
||||
(printf "~a bottle~a of beer~a"
|
||||
(case n [(0) "no more"] [(1) "1"] [else n])
|
||||
(if (= n 1) "" "s")
|
||||
more))
|
||||
|
||||
(for ([n (in-range 99 0 -1)])
|
||||
(bottles n " on the wall, ")
|
||||
(bottles n ".\n")
|
||||
(printf "Take one down and pass it around, ")
|
||||
(bottles (sub1 n) " on the wall.\n\n"))
|
||||
|
||||
(displayln "No more bottles of beer on the wall, no more bottles of beer.")
|
||||
(displayln "Go to the store and buy some more, 99 bottles of beer on the wall.")
|
||||
0
samples/Ruby/ruby2.script!
Normal file → Executable file
0
samples/Ruby/ruby2.script!
Normal file → Executable file
40
samples/Scala/99-bottles-of-beer.script!
Executable file
40
samples/Scala/99-bottles-of-beer.script!
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
exec scala "$0" "$@"
|
||||
!#
|
||||
|
||||
object Beers extends Application {
|
||||
|
||||
def bottles(qty : Int, f : => String) = // higher-order functions
|
||||
qty match {
|
||||
case 0 => "no more bottles of beer" + f
|
||||
case 1 => "1 bottle of beer" + f
|
||||
case x => x + " bottles of beer" + f
|
||||
}
|
||||
|
||||
def beers(qty : Int) = bottles(qty, " on the wall.")
|
||||
|
||||
def sing(qty : Int)(implicit song : String) : String = {
|
||||
def takeOne =
|
||||
qty match {
|
||||
case 0 => "Go to the store and buy some more."
|
||||
case x => "Take one down and pass it around."
|
||||
}
|
||||
|
||||
def nextQty = // nested functions
|
||||
if (qty == 0) 99
|
||||
else qty - 1
|
||||
|
||||
def refrain = {
|
||||
beers(qty).capitalize + " " + bottles(qty, "") + ".\n" +
|
||||
takeOne + " " + beers(nextQty) + "\n\n"
|
||||
}
|
||||
|
||||
if (qty == -1) song
|
||||
else sing(qty - 1)(song + refrain) // tail recursion
|
||||
}
|
||||
|
||||
implicit val headOfSong : String = ""
|
||||
|
||||
println(sing(99)) // implicit parameter
|
||||
|
||||
}
|
||||
0
samples/Shell/plugin.script!
Normal file → Executable file
0
samples/Shell/plugin.script!
Normal file → Executable file
Reference in New Issue
Block a user