Re: Overcoming the "Dylan is Dead" belief?
Alexey Muranov <[email protected]> Fri, 14 Mar 2014 11:04:48 +0100
| Newsgroups | gmane.comp.lang.dylan.gwydion.devel |
|---|---|
| Message-ID | <[email protected]> |
Anticipating the question how i would do conditionals ;) ... maybe like that?
//////////////////////////////////////////////////////////////////////////////
if (test-expression) {
// if test-expression is true
}
: elseif (other-test) {
// otherwise, if other-test is true
}
: else {
// If no tests above were true
}
case { let p1 = player1; let p2 = player2 }
: p1.money <= 0 { end-game(p1) }
: p2.money <= 0 { end-game(p2) }
: otherwise { move(p1); move(p2) }
select (as-uppercase(char))
: 'D' { collect(number-to-string(argument(char, <number>))) }
: 'B' { collect(integer-to-string(argument(char, <integer>), base: 2)) }
: 'O' { collect(integer-to-string(argument(char, <integer>), base: 8)) }
: 'X' { collect(integer-to-string(argument(char, <integer>), base: 16)) }
: 'C' { collect-character(argument(char, <character>)) }
: 'S' { print-pretty-name(buffer, argument(char, <object>)) }
: '=' { print-unique-name(buffer, argument(char, <object>)) }
: '%' { collect-character('%') }
: otherwise {
error("Invalid format directive '%s' in \"%s\"",
char, format-string) }
//////////////////////////////////////////////////////////////////////////////
Alexey.
On 14 mars 2014, at 00:02, Alexey Muranov <[email protected]> wrote:
> I dare to propose here an alternative syntax, for whatever it is worth. I kept thinking about it for a while, because having to type and to visually parse all the semicolons makes me reluctant to use Dylan for scripting. This only reflects my personal taste, please feel free to ignore.
>
> I have thought of something like this, for example:
>
> //////////////////////////////////////////////////////////////////////////////
>
> define class <vehicle> (<object>) {
> slot owner :: <string>,
> init-keyword: owner:,
> init-value: "Northern Motors" }
>
> define class <car> (<vehicle>)
>
> define class <truck> (<vehicle>) {
> slot capacity,
> required-init-keyword: tons: }
>
> //////////////////////////////////////////////////////////////////////////////
>
> define generic tax
> (v :: <vehicle>) => (tax-in-dollars :: <float>)
>
> define method tax
> (v :: <vehicle>) => (tax-in-dollars :: <float>) {
> 100.00 }
>
> define method tax
> (c :: <car>) => (tax-in-dollars :: <float>) {
> 50.0 }
>
> define method tax
> (t :: <truck>) => (tax-in-dollars :: <float>) {
> // standard vehicle tax plus $10/ton
> next-method() + t.capacity * 10.0 }
>
> //////////////////////////////////////////////////////////////////////////////
>
> define function make-fibonacci() {
> let n = 0
> let m = 1
> method () {
> let result = n + m
> n <- m
> m <- result // return value
> } }
>
> define constant fib = make-fibonacci()
>
> for (i from 1 to 15) {
> format-out("%d ", fib()) }
>
> //////////////////////////////////////////////////////////////////////////////
>
> Best,
>
> Alexey.