text stringlengths 0 601k |
|---|
let assignment_variable = cadr ; ; |
let assignment_value = caddr ; ; |
let is_definition exp = is_tagged_list exp define_symbol ; ; |
let definition_variable exp = match ( cadr exp ) with | Symbol _ -> cadr exp | Pair obj -> obj . car | _ -> invalid_arg " Argument is not of type Pair " ; ; |
let make_lambda params body = make_pair lambda_symbol ( make_pair params body ) ; ; |
let definition_value exp = match ( cadr exp ) with | Symbol _ -> caddr exp | Pair _ -> make_lambda ( cdr ( cadr exp ) ) ( cdr ( cdr exp ) ) | _ -> invalid_arg " Argument is not of type Pair " ; ; |
let is_if exp = is_tagged_list exp if_symbol ; ; |
let if_predicate = cadr ; ; |
let if_consequent = caddr ; ; |
let if_alternative exp = match ( cdddr exp ) with | EmptyList -> the_false | alt -> car alt ; ; |
let is_true obj = obj != the_false ; ; |
let is_application = function | Pair _ -> true | _ -> false ; ; |
let operator = car ; ; |
let operands = cdr ; ; |
let is_empty_list = function | EmptyList -> true | _ -> false ; ; |
let is_no_operands = is_empty_list ; ; |
let first_operand = car ; ; |
let rest_operands = cdr ; ; |
let is_lambda exp = is_tagged_list exp lambda_symbol ; ; |
let lambda_parameters = cadr ; ; |
let lambda_body exp = cdr ( cdr exp ) ; ; |
let eval_lambda exp env = let params = lambda_parameters exp and body = lambda_body exp in CompoundProc ( params , body , env ) ; ; |
let is_begin exp = is_tagged_list exp begin_symbol ; ; |
let begin_action = cdr ; ; |
let make_if predicate consequent alternative = make_pair if_symbol ( make_pair predicate ( make_pair consequent ( make_pair alternative EmptyList ) ) ) ; ; |
let make_begin seq = make_pair begin_symbol seq ; ; |
let is_cond exp = is_tagged_list exp cond_symbol ; ; |
let cond_clauses = cdr ; ; |
let cond_predicate = car ; ; |
let cond_action = cdr ; ; |
let is_cond_else_clauses clauses = cond_predicate clauses = else_symbol ; ; |
let sequence_to_exp = function EmptyList -> EmptyList | Pair { car ; cdr = EmptyList } -> car | seq -> make_begin seq ; ; |
let rec expand_clauses = function EmptyList -> the_false | Pair { car ; cdr } -> begin if is_cond_else_clauses car then if cdr = EmptyList then sequence_to_exp ( cond_action car ) else begin prerr_string " else clause isn ' t last cond -> if \ n " ; raise Exit end else make_if ( cond_predicate car ) ( sequence_to_exp (... |
let cond_to_if exp = expand_clauses ( cond_clauses exp ) ; ; |
let is_let exp = is_tagged_list exp let_symbol ; ; |
let make_application = make_pair ; ; |
let let_bindings = cadr ; ; |
let rec bindings_parameters = function EmptyList -> EmptyList | Pair { car = binding ; cdr = rest } -> make_pair ( car binding ) ( bindings_parameters rest ) | _ -> invalid_arg " Impossible -- bindings_parameters " ; ; |
let let_parameters exp = bindings_parameters ( let_bindings exp ) ; ; |
let let_body = cddr ; ; |
let rec bindings_arguments = function EmptyList -> EmptyList | Pair { car = binding ; cdr = rest } -> make_pair ( cadr binding ) ( bindings_arguments rest ) | _ -> invalid_arg " Impossible -- bindings_parameters " ; ; |
let let_arguments exp = bindings_arguments ( let_bindings exp ) ; ; |
let let_to_application exp = make_application ( make_lambda ( let_parameters exp ) ( let_body exp ) ) ( let_arguments exp ) ; ; |
let is_and exp = is_tagged_list exp and_symbol ; ; |
let is_or exp = is_tagged_list exp or_symbol ; ; |
let or_tests = cdr ; ; |
let and_tests = cdr ; ; |
let is_false = ( ) = the_false ; ; |
let rec list_of_values exps env = if is_no_operands exps then EmptyList else make_pair ( eval ( first_operand exps ) env ) ( list_of_values ( rest_operands exps ) env ) begin set_variable_value ( assignment_variable exp ) ( eval ( assignment_value exp ) env ) env ; ok_symbol end begin define_variable ( definition_varia... |
let write_string str = begin print_char ' " ' ; String . iter ( fun c -> match c with | ' \ n ' -> print_string " \\ n " | ' ' \\ -> print_string " " \\\\ | c when c = ' " ' -> print_string " " " \\\ | c -> print_char c ) str ; print_char ' " ' end ; ; |
let write_character = function ' \ n ' -> print_string " #\\ newline " | ' ' -> print_string " #\\ space " | c -> Printf . printf " #\\% c " c ; ; |
let rec write_pair = function Pair { car ; cdr } -> begin write car ; match cdr with | EmptyList -> ( ) | Pair _ -> ( print_char ' ' ; write_pair cdr ) | _ -> ( print_string " . " ; write cdr ) end | _ -> invalid_arg " Not a pair " match obj with | Fixnum num -> Printf . printf " % d " num | Boolean true -> print_strin... |
let global_environment = setup_environment ( ) ; ; |
let add_proc args = let rec aux = function EmptyList -> 0 | Pair { car = Fixnum n ; cdr = ns } -> n + aux ns | _ -> invalid_arg " All arguments must be of type fixnum " in Fixnum ( aux args ) ; ; |
let sub_proc args = let rec aux acc rest = match rest with | EmptyList -> acc | Pair { car = Fixnum n ; cdr = ns } -> aux ( acc - n ) ns | _ -> invalid_arg " All arguments must be of type fixnum " in match args with | EmptyList -> Fixnum 0 | Pair { car = Fixnum n ; cdr = rest } -> Fixnum ( aux n rest ) | _ -> invalid_a... |
let mul_proc args = let rec aux = function EmptyList -> 1 | Pair { car = Fixnum n ; cdr = ns } -> n * aux ns | _ -> invalid_arg " Argument must be of type Fixnum " in Fixnum ( aux args ) ; ; |
let quotient_proc args = match args with | Pair { car = Fixnum a ; cdr = Pair { car = Fixnum b ; cdr = EmptyList } } -> Fixnum ( a / b ) | _ -> invalid_arg " Argument muse be a proper list contains two fixnums " ; ; |
let remainder_proc args = match args with | Pair { car = Fixnum a ; cdr = Pair { car = Fixnum b ; cdr = EmptyList } } -> Fixnum ( a mod b ) | _ -> invalid_arg " Argument muse be a proper list contains two fixnums " ; ; |
let is_number_equal_proc args = let rec aux cur rest = match rest with | EmptyList -> the_true | Pair { car = Fixnum n ; cdr = ns } -> if cur = n then aux n ns else the_false | _ -> invalid_arg " Argument must be of type Fixnum " in match args with | Pair { car = Fixnum cur ; cdr = rest } -> aux cur rest | _ -> invalid... |
let is_less_than_proc args = let rec aux cur rest = match rest with | EmptyList -> the_true | Pair { car = Fixnum n ; cdr = ns } -> if cur < n then aux n ns else the_false | _ -> invalid_arg " Argument must be of type Fixnum " in match args with | Pair { car = Fixnum cur ; cdr = rest } -> aux cur rest | _ -> invalid_ar... |
let is_greater_than_proc args = let rec aux cur rest = match rest with | EmptyList -> the_true | Pair { car = Fixnum n ; cdr = ns } -> if cur > n then aux n ns else the_false | _ -> invalid_arg " Argument must be of type Fixnum " in match args with | Pair { car = Fixnum cur ; cdr = rest } -> aux cur rest | _ -> invalid... |
let cons_proc = function Pair { car ; cdr = Pair { cdr = obj ; _ } } -> make_pair car obj | _ -> invalid_arg " Arguments must be a proper list contains two objects " ; ; |
let car_proc = function Pair { car = Pair { car ; _ } ; cdr = EmptyList } -> car | _ -> invalid_arg " Arguments must be a proper list contains one Pair " ; ; |
let cdr_proc = function Pair { car = Pair { car = _ ; cdr } ; cdr = EmptyList } -> cdr | _ -> invalid_arg " Arguments must be a proper list contains one Pair " ; ; |
let set_car_proc = function Pair { car = Pair obj ; cdr = value } -> ( obj . car <- car value ; ok_symbol ) | _ -> invalid_arg " Arguments must be a proper list contains two objects " ; ; |
let set_cdr_proc = function Pair { car = Pair obj ; cdr = value } -> ( obj . cdr <- cdr value ; ok_symbol ) | _ -> invalid_arg " Arguments must be a proper list contains two objects " ; ; |
let list_proc args = args ; ; |
let is_null_proc = function Pair { car = EmptyList ; _ } -> the_true | _ -> the_false ; ; |
let is_boolean_proc = function Pair { car = Boolean _ ; _ } -> the_true | _ -> the_false ; ; |
let is_symbol_proc = function Pair { car = Symbol _ ; _ } -> the_true | _ -> the_false ; ; |
let is_integer_proc = function Pair { car = Fixnum _ ; _ } -> the_true | _ -> the_false ; ; |
let is_char_proc = function Pair { car = Character _ ; _ } -> the_true | _ -> the_false ; ; |
let is_string_proc = function Pair { car = String _ ; _ } -> the_true | _ -> the_false ; ; |
let is_pair_proc = function Pair { car = Pair _ ; _ } -> the_true | _ -> the_false ; ; |
let char_to_integer_proc = function Pair { car = Character c ; _ } -> Fixnum ( Char . code c ) | _ -> invalid_arg " Argument is not of type Character " ; ; |
let integer_to_char_proc = function Pair { car = Fixnum num ; _ } -> Character ( Char . chr num ) | _ -> invalid_arg " Argument is not of type Fixnum " ; ; |
let number_to_string_proc = function Pair { car = Fixnum num ; _ } -> String ( string_of_int num ) | _ -> invalid_arg " Argument is not of type Fixnum " ; ; |
let string_to_number_proc = function Pair { car = String str ; _ } -> Fixnum ( int_of_string str ) | _ -> invalid_arg " Argument is not of type String " ; ; |
let symbol_to_string_proc = function Pair { car = Symbol name ; _ } -> String name | _ -> invalid_arg " Argument is not of type Symbol " ; ; |
let string_to_symbol_proc = function Pair { car = String str ; _ } -> make_symbol str | _ -> invalid_arg " Argument is not of type String " ; ; |
let add_primitive_procedure name fn = define_variable ( make_symbol name ) ( PrimitiveProc fn ) global_environment ; ; |
let is_eq_proc args = let obj1 = car args and obj2 = cadr args in match obj1 , obj2 with | Fixnum n , Fixnum m -> if n = m then the_true else the_false | Character c , Character d -> if c = d then the_true else the_false | a , b -> if a == b then the_true else the_false ; ; |
let init ( ) = let kvs = [ ( " " , + add_proc ) ; ( " null " , ? is_null_proc ) ; ( " boolean " , ? is_boolean_proc ) ; ( " symbol " , ? is_symbol_proc ) ; ( " integer " , ? is_integer_proc ) ; ( " char " , ? is_char_proc ) ; ( " string " , ? is_string_proc ) ; ( " pair " , ? is_pair_proc ) ; ( " char -> integer " , ch... |
let main ( ) = begin init ( ) ; print_string " Welcome to Bootstrap Scheme . Use ctrl - c to exit . \ n " ; flush stdout ; while true do print_string " > " ; flush stdout ; write ( eval ( read stdin ) global_environment ) ; print_newline ( ) done ; 0 end ; ; |
let rep ( ) = write ( eval ( read stdin ) global_environment ) ; ; |
let ( ) = init ( ) |
let print = Printf . printf " % s \ n " |
module Directory_rules = struct type element = | File of string | Thunk of ( unit -> t ) and t = element Appendable_list . t let empty = Appendable_list . empty let union = Appendable_list . ( @ ) let concat t = List . fold_left t ~ init : empty ~ f : union let thunk f = Appendable_list . singleton ( Thunk f ) let file... |
module Scheme = struct include Dune_rules . Scheme let instrument ~ print = let print path suffix = print ( String . concat ( List . rev path @ [ suffix ] ) ~ sep " " ) :: in let rec go ~ path t = match t with | Empty -> Empty | Union ( t1 , t2 ) -> Union ( go ~ path ( " : l " :: path ) t1 , go ~ path ( " : r " :: path... |
module Path = struct include Path . Build let of_string str = L . relative root ( match String . split str ~ on ' ' :/ with | [ " " ] -> [ ] | [ " . " ] -> [ ] | other -> other ) end |
let record_calls scheme ~ f = let calls = ref [ ] in let scheme = Scheme . instrument ~ print ( : fun s -> calls := s :: ! calls ) scheme in let + res = f scheme in ( Directory_rules . force res , ! calls ) |
let print_rules scheme ~ dir = let * res1 , calls1 = record_calls scheme ~ f ( : Scheme . collect_rules_simple ~ dir ) in let + res2 , calls2 = record_calls scheme ~ f ( : fun scheme -> Scheme . evaluate scheme >>= Scheme . get_rules ~ dir ) in if not ( ( res1 : string list ) = res2 ) then Code_error . raise " Naive [ ... |
let run m = Fiber . run ( Memo . run m ) ~ iter ( : fun ( ) -> assert false ) |
let print_rules scheme ~ dir = run @@ print_rules scheme ~ dir let scheme = Scheme . Thunk ( fun ( ) -> Memo . return Scheme . Empty ) in print_rules scheme ~ dir ( : Path . of_string " foo / bar " ) ; [ % expect { | calls : thunk rules : < none > } ] | |
let scheme_all_but_foo_bar = Scheme . Approximation ( Dir_set . negate ( Dir_set . subtree ( Path . of_string " foo / bar " ) ) , Thunk ( fun ( ) -> Memo . return Empty ) ) print_rules scheme_all_but_foo_bar ~ dir ( : Path . of_string " unrelated / dir " ) ; [ % expect { | calls : t : thunk rules : < none > } ] | print... |
module type Message_intf = sig type field type t type curve type curve_scalar val derive : t -> private_key : curve_scalar -> public_key : curve -> curve_scalar val derive_for_mainnet : t -> private_key : curve_scalar -> public_key : curve -> curve_scalar val derive_for_testnet : t -> private_key : curve_scalar -> publ... |
module type S = sig module Impl : Snarky_backendless . Snark_intf . S open Impl type curve type curve_var type curve_scalar type curve_scalar_var module Shifted : sig module type S = Snarky_curves . Shifted_intf with type curve_var := curve_var and type boolean_var := Boolean . var and type ' a checked := ' a Checked .... |
module Make ( Impl : Snarky_backendless . Snark_intf . S ) S ( Curve : sig open Impl module Scalar : sig type t [ @@ deriving sexp , equal ] equal type var val typ : ( var , t ) t Typ . t val zero : t val ( * ) : t -> t -> t val ( + ) : t -> t -> t val negate : t -> t module Checked : sig val to_bits : var -> Boolean .... |
module type S = sig open Snark_params . Tick type curve type curve_scalar module Message : Message_intf with type curve_scalar := curve_scalar and type curve := curve and type field := Field . t module Signature : sig type t = Field . t * curve_scalar [ @@ deriving sexp ] sexp end module Private_key : sig type t = curv... |
module Make ( Impl : module type of Snark_params . Tick ) Tick ( Curve : sig open Impl module Scalar : sig type t [ @@ deriving sexp , equal ] equal val zero : t val ( * ) : t -> t -> t val ( + ) : t -> t -> t val negate : t -> t end type t [ @@ deriving sexp ] sexp val one : t val ( + ) : t -> t -> t val negate : t ->... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.