September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -0,0 +1 @@
--- {}

View file

@ -0,0 +1,30 @@
(declaim (inline no-args))
(declaim (inline one-arg))
(declaim (inline two-args))
(declaim (inline optional-args))
(defun no-args ()
(format nil "no arguments!"))
(defun one-arg (x)
; inserts the value of x into a string
(format nil "~a" x))
(defun two-args (x y)
; same as function `one-arg', but with two arguments
(format nil "~a ~a" x y))
(defun optional-args (x &optional y) ; optional args are denoted with &optional beforehand
; same as function `two-args', but if y is not given it just prints NIL
(format nil "~a ~a~%" x y))
(no-args) ;=> "no arguments!"
(one-arg 1) ;=> "1"
(two-args 1 "example") ;=> "1 example"
(optional-args 1.0) ;=> "1.0 NIL"
(optional-args 1.0 "example") ;=> "1.0 example"

View file

@ -0,0 +1,2 @@
add :: Int -> Int -> Int
add x y = x+y

View file

@ -0,0 +1 @@
add :: Int->(Int ->(Int->Int))

View file

@ -0,0 +1 @@
printThis = putStrLn("This is being printed.")

View file

@ -0,0 +1,2 @@
add :: Int -> Int -> Int
add x y = x+y

View file

@ -0,0 +1,2 @@
add :: Int -> Int -> Int
add = \x->\y -> x+y

View file

@ -0,0 +1,2 @@
doThis :: Int-> Int-> String
doThis _ _ = "Function with unnamed parameters"

View file

@ -0,0 +1,4 @@
julia > function mycompare(a, b)::Cint
(a < b) ? -1 : ((a > b) ? +1 : 0)
end
mycompare (generic function with 1 method)

View file

@ -0,0 +1 @@
julia> mycompare_c = @cfunction(mycompare, Cint, (Ref{Cdouble}, Ref{Cdouble}))

View file

@ -0,0 +1,24 @@
(* Usually prototype declarations are put in an interface file,
a file with .mli filename extension *)
(* A prototype declaration for a function that does not require arguments *)
val no_arg : unit -> unit
(* A prototype declaration for a function that requires two arguments *)
val two_args : int -> int -> unit
(* A prototype declaration for a function that utilizes optional arguments *)
val opt_arg : ?param:int -> unit -> unit
(* in this case we add a unit parameter in order to omit the argument,
because ocaml supports partial application *)
(* A prototype declaration for a function that utilizes named parameters *)
val named_arg : param1:int -> param2:int -> unit
(* An explanation and example of any special forms of prototyping not covered by the above *)
(* A prototype declaration for a function that requires a function argument *)
val fun_arg : (int -> int) -> unit
(* A prototype declaration for a function with polymorphic argument *)
val poly_arg : 'a -> unit

View file

@ -0,0 +1,77 @@
;Forward procedure declare defined with no arguments and that returns a string
Declare.s booTwo()
;Forward procedure declare defined with two arguments and that returns a float
Declare.f moo(x.f, y.f)
;Forward procedure declare with two arguments and an optional argument and that returns a float
Declare.f cmoo(x.f, y.f, m.f = 0)
;*** The following three procedures are defined before their first use.
;Procedure defined with no arguments and that returns a string
Procedure.s boo(): ProcedureReturn "boo": EndProcedure
;Procedure defined with two arguments and that returns an float
Procedure.f aoo(x.f, y.f): ProcedureReturn x + y: EndProcedure
;Procedure defined with two arguments and an optional argument and that returns a float
Procedure.f caoo(x.f, y.f, m.f = 1): ProcedureReturn (x + y) * m: EndProcedure
;ProtoType defined for any function with no arguments and that returns a string
Prototype.s showString()
;Prototype defined for any function with two float arguments and that returns a float
Prototype.f doMath(x.f, y.f)
;ProtoType defined for any function with two float arguments and an optional float argument and that returns a float
Prototype.f doMathWithOpt(x.f, y.f, m.f = 0)
Define a.f = 12, b.f = 5, c.f = 9
Define proc_1.showString, proc_2.doMath, proc_3.doMathWithOpt ;using defined ProtoTypes
If OpenConsole("ProtoTypes and Forward Declarations")
PrintN("Forward Declared procedures:")
PrintN(boo())
PrintN(StrF(a, 2) + " * " + StrF(b, 2) + " = " + StrF(moo(a, b), 2))
PrintN(StrF(a, 2) + " * " + StrF(b, 2) + " + " + StrF(c, 2) + " = " + StrF(cmoo(a, b, c), 2))
PrintN(StrF(a, 2) + " * " + StrF(b, 2) + " = " + StrF(cmoo(a, b), 2))
;set pointers to second set of functions
proc_1 = @boo()
proc_2 = @aoo()
proc_3 = @caoo()
PrintN("ProtoTyped procedures (set 1):")
PrintN(proc_1())
PrintN(StrF(a, 2) + " ? " + StrF(b, 2) + " = " + StrF(proc_2(a, b), 2))
PrintN(StrF(a, 2) + " ? " + StrF(b, 2) + " ? " + StrF(c, 2) + " = " + StrF(proc_3(a, b, c), 2))
PrintN(StrF(a, 2) + " ? " + StrF(b, 2) + " = " + StrF(proc_3(a, b), 2))
;set pointers to second set of functions
proc_1 = @booTwo()
proc_2 = @moo()
proc_3 = @cmoo()
PrintN("ProtoTyped procedures (set 2):")
PrintN(proc_1())
PrintN(StrF(a, 2) + " ? " + StrF(b, 2) + " = " + StrF(proc_2(a, b), 2))
PrintN(StrF(a, 2) + " ? " + StrF(b, 2) + " ? " + StrF(c, 2) + " = " + StrF(proc_3(a, b, c), 2))
PrintN(StrF(a, 2) + " ? " + StrF(b, 2) + " = " + StrF(proc_3(a, b), 2))
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf
;*** If the forward Declaration above are not used then the following Procedure
;definitions each have to be placed before the call to the respective procedure.
;Procedure defined with no arguments and that returns a string
Procedure.s booTwo()
ProcedureReturn "booTwo"
EndProcedure
;Procedure defined with two arguments and that returns an float
Procedure.f moo(x.f, y.f)
ProcedureReturn x * y
EndProcedure
;Procedure defined with two arguments and an optional argument and that returns an float
Procedure.f cmoo(x.f, y.f, m.f = 0)
ProcedureReturn (x * y) + m
EndProcedure