![]() ) ( let () "Alice" me ) => "Bob" let* is like let, but allows you to use previous bindings in creating later bindings ( let* ( ) ( * x y )) finally, letrec allows you to define recursive and mutually recursive functions ( letrec ( ) ( is-odd? 11 )) 3. Local binding: `me' is bound to "Bob" only within the (let. Variables You can create a variable using define a variable name can use any character except: ()",'` #|\ ( define some-var 5 ) some-var => 5 You can also use unicode characters ( define ⊆ subset? ) ( ⊆ ( set 3 2 ) ( set 1 2 3 )) => #t Accessing a previously unassigned variable is an exception x => x: undefined. "Hello, world!" "Benjamin \" Bugsy \" Siegel" backslash is an escaping character "Foo \t bar \41\x21\u0021\a\r\n " includes C escapes, Unicode "λx:(μα.α→α).xx" can include Unicode characters Strings can be added too! ( string-append "Hello " "world!" ) => "Hello world!" A string can be treated like a list of characters ( string-ref "Apple" 0 ) => #\A format can be used to format strings: ( format "~a can be ~a" "strings" "formatted" ) Printing is pretty easy ( printf "I'm Racket. are operands If you want to create a literal list of data, use ' to stop it from being evaluated ' ( 1 2 ) => ( 1 2) Now, some arithmetic operations ( 1 1 ) => 2 ( - 8 1 ) => 7 ( * 10 2 ) => 20 ( expt 2 3 ) => 8 ( quotient 5 2 ) => 2 ( remainder 5 2 ) => 1 ( / 35 5 ) => 7 ( / 1 3 ) => 1/3 ( exact->inexact 1/3 ) => 0.3333333333333333 ( 1 2i 2-3i ) => 3-1i Booleans #t for true #f for false - any value other than #f is true ( not #t ) => #f ( and 0 #f ( error "doesn't get here" )) => #f ( or #f 0 ( error "doesn't get here" )) => 0 Characters #\A => #\A #\λ => #\λ #\u03BB => #\λ Strings are fixed-length array of characters. Primitive Datatypes and Operators Numbers 9999999999999999999999 integers #b111 binary => 7 #o111 octal => 73 #x111 hexadecimal => 273 3.14 reals 6.02e 23 1/2 rationals 1 2i complex numbers Function application is written (f x y z. #| they can be nested! |# |# S-expression comments discard the following expression, useful to comment expressions when debugging # ( this expression is discarded ) 1. #lang racket defines the language we are using Comments Single line comments start with a semicolon #| Block comments can span multiple lines and.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |