1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 /* Any copyright is dedicated to the Public Domain.
12 * http://creativecommons.org/publicdomain/zero/1.0/ */
15 use std::io::stdio::println;
17 fn call_it(f: proc(~str) -> ~str) {
18 println!("{}", f(~"Fred"))
21 fn call_a_thunk(f: ||) {
25 fn call_this(f: |&str|:Send) {
29 fn call_that(f: <'a>|&'a int, &'a int|: -> int) {
30 let (ten, forty_two) = (10, 42);
31 println!("Your lucky number is {}", f(&ten, &forty_two));
34 fn call_cramped(f:||->uint,g:<'a>||->&'a uint) {
36 let other_number = *g();
37 println!("Ticket {} wins an all-expenses-paid trip to Mountain View", number + other_number);
40 fn call_bare(f: fn(&str)) {
44 fn call_bare_again(f: extern "Rust" fn(&str)) {
51 let greeting = ~"Hello ";
56 let greeting = ~"Goodbye ";
57 call_it(proc(s) greeting + s);
59 let greeting = ~"How's life, ";
60 call_it(proc(s: ~str) -> ~str {
66 call_a_thunk(|| println!("Hello world!"));
68 call_this(|s| println!("{}", s));
70 call_that(|x, y| *x + *y);
73 call_that(|x, y| *x + *y - z);
75 call_cramped(|| 1, || unsafe {
84 call_bare_again(println);