├── LICENSE ├── README.md ├── build.bat ├── examples ├── amb.ss ├── church_encoding.ss ├── coroutine.ss ├── evaluator.ss ├── fib_benchmark.ss ├── fibc.ss ├── infinite.ss ├── list_test.ss ├── macro.ss ├── prime_generator.ss └── testcode.ss ├── lib └── nunit.framework.dll ├── schemin.nunit └── src ├── Schemin.sln ├── Schemin ├── Assembly │ └── AssemblyInfo.cs ├── Mono.Options │ └── Options.cs ├── Program.cs ├── Schemin.AST │ ├── AtomFactory.cs │ ├── IScheminNumeric.cs │ ├── IScheminType.cs │ ├── ScheminAtom.cs │ ├── ScheminBool.cs │ ├── ScheminChar.cs │ ├── ScheminContinuation.cs │ ├── ScheminDecimal.cs │ ├── ScheminInteger.cs │ ├── ScheminLambda.cs │ ├── ScheminPair.cs │ ├── ScheminPort.cs │ ├── ScheminPrimitive.cs │ ├── ScheminRewriter.cs │ ├── ScheminString.cs │ └── ScheminVector.cs ├── Schemin.Evaluate │ ├── Environment.cs │ ├── Evaluator.cs │ ├── MacroExpander.cs │ ├── StackFrame.cs │ └── UnboundAtomException.cs ├── Schemin.Interpret │ └── Interpreter.cs ├── Schemin.Parse │ └── PairParser.cs ├── Schemin.Primitives │ ├── BadArgumentsException.cs │ ├── Primitive.cs │ ├── PrimitiveFactory.cs │ ├── Schemin.Primitives.BooleanOperations │ │ ├── And.cs │ │ ├── Boolean.cs │ │ ├── Char.cs │ │ ├── EOFObject.cs │ │ ├── Eq.cs │ │ ├── Equal.cs │ │ ├── Eqv.cs │ │ ├── GreaterThan.cs │ │ ├── GreaterThanOr.cs │ │ ├── InputPort.cs │ │ ├── LessThan.cs │ │ ├── LessThanOr.cs │ │ ├── List.cs │ │ ├── Null.cs │ │ ├── Number.cs │ │ ├── NumericalEqual.cs │ │ ├── Or.cs │ │ ├── OutputPort.cs │ │ ├── Pair.cs │ │ ├── Port.cs │ │ ├── Prime.cs │ │ ├── Procedure.cs │ │ ├── String.cs │ │ ├── Symbol.cs │ │ └── Vector.cs │ ├── Schemin.Primitives.CharOperations │ │ ├── CharAlphabetic.cs │ │ ├── CharDowncase.cs │ │ ├── CharEquals.cs │ │ ├── CharGreaterThan.cs │ │ ├── CharGreaterThanOr.cs │ │ ├── CharInteger.cs │ │ ├── CharLessThan.cs │ │ ├── CharLessThanOr.cs │ │ ├── CharLowerCase.cs │ │ ├── CharNumeric.cs │ │ ├── CharUpcase.cs │ │ ├── CharUpperCase.cs │ │ ├── CharWhitespace.cs │ │ └── IntegerChar.cs │ ├── Schemin.Primitives.GeneralOperations │ │ ├── Apply.cs │ │ ├── Begin.cs │ │ ├── CallCC.cs │ │ ├── Case.cs │ │ ├── Cond.cs │ │ ├── Define.cs │ │ ├── DefineRewriter.cs │ │ ├── DumpEnv.cs │ │ ├── Eval.cs │ │ ├── Expand.cs │ │ ├── GenSym.cs │ │ ├── If.cs │ │ ├── Lambda.cs │ │ ├── Let.cs │ │ ├── LetRec.cs │ │ ├── LetStar.cs │ │ ├── Load.cs │ │ ├── QuasiQuote.cs │ │ ├── Quote.cs │ │ └── SetBang.cs │ ├── Schemin.Primitives.ListOperations │ │ ├── Append.cs │ │ ├── Car.cs │ │ ├── Cdr.cs │ │ ├── Cons.cs │ │ ├── Length.cs │ │ ├── List.cs │ │ ├── Reverse.cs │ │ ├── SetCar.cs │ │ └── SetCdr.cs │ ├── Schemin.Primitives.NumericOperations │ │ ├── Add.cs │ │ ├── Divide.cs │ │ ├── Mod.cs │ │ ├── Multiply.cs │ │ ├── NumberString.cs │ │ └── Subtract.cs │ ├── Schemin.Primitives.PortOperations │ │ ├── ClosePort.cs │ │ ├── CurrentInputPort.cs │ │ ├── CurrentOutputPort.cs │ │ ├── Display.cs │ │ ├── Newline.cs │ │ ├── OpenInputFile.cs │ │ ├── OpenOutputFile.cs │ │ ├── PortClosed.cs │ │ ├── Read.cs │ │ ├── ReadChar.cs │ │ ├── ReadLine.cs │ │ ├── SetCurrentInputPort.cs │ │ ├── SetCurrentOutputPort.cs │ │ ├── Write.cs │ │ └── WriteChar.cs │ ├── Schemin.Primitives.StringOperations │ │ ├── ListString.cs │ │ ├── StringAppend.cs │ │ ├── StringLength.cs │ │ ├── StringList.cs │ │ ├── StringRef.cs │ │ └── Substring.cs │ ├── Schemin.Primitives.SymbolOperations │ │ ├── CreateClosedSymbol.cs │ │ ├── StringSymbol.cs │ │ └── SymbolString.cs │ └── Schemin.Primitives.VectorOperations │ │ ├── ListVector.cs │ │ ├── MakeVector.cs │ │ ├── Vector.cs │ │ ├── VectorFill.cs │ │ ├── VectorLength.cs │ │ ├── VectorList.cs │ │ ├── VectorRef.cs │ │ └── VectorSet.cs ├── Schemin.Tokenize │ ├── Token.cs │ ├── TokenType.cs │ └── Tokenizer.cs └── Schemin.csproj ├── ScheminLib └── ScheminLib.ss └── ScheminTests ├── Assembly └── AssemblyInfo.cs ├── ScheminTests.PrimitiveTests ├── NumericOperationTests.cs └── StringOperationTests.cs └── ScheminTests.csproj /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Alex Fort 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 3. The name of the author may not be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /build.bat: -------------------------------------------------------------------------------- 1 | @%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\msbuild %~dp0src\Schemin.sln /t:Build /verbosity:n 2 | -------------------------------------------------------------------------------- /examples/amb.ss: -------------------------------------------------------------------------------- 1 | ; current-continuation : -> continuation 2 | (define (current-continuation) 3 | (call-with-current-continuation 4 | (lambda (cc) 5 | (cc cc)))) 6 | 7 | ; fail-stack : list[continuation] 8 | (define fail-stack '()) 9 | 10 | ; fail : -> ... 11 | (define (fail) 12 | (if (not (pair? fail-stack)) 13 | (error "back-tracking stack exhausted!") 14 | (begin 15 | (let ((back-track-point (car fail-stack))) 16 | (set! fail-stack (cdr fail-stack)) 17 | (back-track-point back-track-point))))) 18 | 19 | ; amb : list[a] -> a 20 | (define (amb choices) 21 | (let ((cc (current-continuation))) 22 | (if (null? choices) (fail) 23 | (if (pair? choices) (let ((choice (car choices))) 24 | (set! choices (cdr choices)) 25 | (set! fail-stack (cons cc fail-stack)) 26 | choice))))) 27 | 28 | ; (assert condition) will cause 29 | ; condition to be true, and if there 30 | ; is no way to make it true, then 31 | ; it signals and error in the program. 32 | (define (assert condition) 33 | (if (not condition) 34 | (fail) 35 | #t)) 36 | 37 | 38 | ; The following prints (4 3 5) 39 | (let ((a (amb (list 1 2 3 4 5 6 7))) 40 | (b (amb (list 1 2 3 4 5 6 7))) 41 | (c (amb (list 1 2 3 4 5 6 7)))) 42 | 43 | ; We're looking for dimensions of a legal right 44 | ; triangle using the Pythagorean theorem: 45 | ; And, we want the second side to be the shorter one: 46 | (assert (= (* c c) (+ (* a a) (* b b)))) 47 | (assert (< b a)) 48 | 49 | ; Print out the answer: 50 | (display (list a b c)) 51 | (newline)) 52 | 53 | 54 | ; Generate a prime from a list of numbers.. 55 | (let ((a (amb (list 14 15 16 17 18 19)))) 56 | (assert (prime? a)) 57 | ; Print out the answer: 58 | (display a) 59 | (newline)) 60 | -------------------------------------------------------------------------------- /examples/coroutine.ss: -------------------------------------------------------------------------------- 1 | ; Stolen from: http://matt.might.net/articles/programming-with-continuations--exceptions-backtracking-search-threads-generators-coroutines/ 2 | 3 | ; thread-queue : list[continuation] 4 | (define thread-queue '()) 5 | 6 | ; halt : continuation 7 | (define halt #f) 8 | 9 | ; void : -> void 10 | (define (void) (if #f #t)) 11 | 12 | ; current-continuation : -> continuation 13 | (define (current-continuation) 14 | (call-with-current-continuation 15 | (lambda (cc) 16 | (cc cc)))) 17 | 18 | ; spawn : (-> anything) -> void 19 | (define (spawn thunk) 20 | (let ((cc (current-continuation))) 21 | (if (procedure? cc) 22 | (set! thread-queue (append thread-queue (list cc))) 23 | (begin (thunk) 24 | (quit))))) 25 | 26 | ; yield : value -> void 27 | (define (yield) 28 | (let ((cc (current-continuation))) 29 | (if (and (procedure? cc) (pair? thread-queue)) 30 | (let ((next-thread (car thread-queue))) 31 | (set! thread-queue (append (cdr thread-queue) (list cc))) 32 | (next-thread 'resume)) 33 | (void)))) 34 | 35 | ; quit : -> ... 36 | (define (quit) 37 | (if (pair? thread-queue) 38 | (let ((next-thread (car thread-queue))) 39 | (set! thread-queue (cdr thread-queue)) 40 | (next-thread 'resume)) 41 | (halt))) 42 | 43 | ; start-threads : -> ... 44 | (define (start-threads) 45 | (let ((cc (current-continuation))) 46 | (if cc 47 | (begin 48 | (set! halt (lambda () (cc #f))) 49 | (if (null? thread-queue) 50 | (void) 51 | (begin 52 | (let ((next-thread (car thread-queue))) 53 | (set! thread-queue (cdr thread-queue)) 54 | (next-thread 'resume))))) 55 | (void)))) 56 | 57 | ;; Example cooperatively threaded program 58 | (define counter 10) 59 | 60 | (define (make-thread-thunk name) 61 | (letrec ((loop (lambda () 62 | (if (< counter 0) 63 | (quit)) 64 | (display "in thread ") 65 | (display name) 66 | (display "; counter = ") 67 | (display counter) 68 | (newline) 69 | (set! counter (- counter 1)) 70 | (yield) 71 | (loop)))) 72 | loop)) 73 | 74 | (spawn (make-thread-thunk 'a)) 75 | (spawn (make-thread-thunk 'b)) 76 | (spawn (make-thread-thunk 'c)) 77 | 78 | (start-threads) 79 | -------------------------------------------------------------------------------- /examples/fib_benchmark.ss: -------------------------------------------------------------------------------- 1 | (define x 30) 2 | (define fib (lambda (n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))) 3 | (fib x) 4 | 5 | -------------------------------------------------------------------------------- /examples/fibc.ss: -------------------------------------------------------------------------------- 1 | (define (succ n) (+ n 1)) 2 | (define (pred n) (- n 1)) 3 | 4 | (define (addc x y k) 5 | (if (zero? y) 6 | (k x) 7 | (addc (succ x) (pred y) k))) 8 | 9 | (define (fibc x c) 10 | (if (zero? x) 11 | (c 0) 12 | (if (zero? (pred x)) 13 | (c 1) 14 | (addc (call-with-current-continuation 15 | (lambda (c) (fibc (pred x) c))) 16 | (call-with-current-continuation 17 | (lambda (c) (fibc (pred (pred x)) c))) 18 | c)))) 19 | 20 | (fibc 20 id) 21 | -------------------------------------------------------------------------------- /examples/macro.ss: -------------------------------------------------------------------------------- 1 | ;; Testing out macros with out own implementation of if, using lambdas as true and false 2 | 3 | (define true 4 | (lambda (x y) x)) 5 | 6 | (define false 7 | (lambda (x y) y)) 8 | 9 | (define-rewriter if-test 10 | (lambda (form rename) 11 | (let ((test (car (cdr form))) 12 | (then (car (cdr (cdr form)))) 13 | (else (car (cdr (cdr (cdr form)))))) 14 | `((,test (,(rename 'lambda) () ,then) (,(rename 'lambda) () ,else)))))) 15 | 16 | 17 | ;; Implementation of a recursive begin macro, using lambdas to force order of evaluation 18 | 19 | (define-rewriter mybegin 20 | (lambda (form rename) 21 | (let ((first (cadr form)) 22 | (rest (cddr form)) 23 | (unused (gensym))) 24 | `((,(rename 'lambda) (,unused) ('mybegin ,rest)) ,first)))) 25 | 26 | 27 | ;; Test stream implementation 28 | 29 | (define-rewriter stream 30 | (lambda (form rename) 31 | (let ((arg1 (cadr form)) 32 | (arg2 (caddr form))) 33 | `(,(rename 'cons) ,arg1 (,(rename 'lambda) () ,arg2))))) 34 | 35 | (define stream-ref 36 | (lambda (s n) 37 | (if (zero? n) 38 | (car s) 39 | (stream-ref ((cdr s)) (- n 1))))) 40 | 41 | (define integers 42 | (lambda (n) 43 | (stream n (integers (+ n 1))))) 44 | -------------------------------------------------------------------------------- /examples/prime_generator.ss: -------------------------------------------------------------------------------- 1 | ;;;; Shamelessly stolen from: https://bitbucket.org/tarballs_are_good/scheme-random 2 | 3 | ;;;; call/cc stuff 4 | ;;;; (c) 2010 Robert Smith 5 | 6 | ;;;; Load this up and call (get-next-prime) 7 | 8 | (define get-next-prime 9 | (letrec 10 | ((entry 11 | (lambda (v) ;; v can be used as a resume value if desired 12 | (let LOOP ((i 2)) 13 | (if (prime? i) 14 | (yield i)) 15 | (LOOP (+ i 1))))) 16 | (exit #f) ;; exit will be set by coroutine below 17 | (yield 18 | (lambda (yield-value) 19 | (call/cc 20 | (lambda (k) 21 | (set! entry k) 22 | (exit yield-value))))) 23 | (coroutine 24 | (lambda (v) ;; v can be used as a resume value since it's 25 | ;; passed to ENTRY 26 | (call/cc 27 | (lambda (k) 28 | (set! exit k) 29 | (entry v)))))) 30 | (lambda () (coroutine #f)))) 31 | 32 | 33 | 34 | (define test-list '(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)) 35 | (define primes (map get-next-prime test-list)) 36 | (display "Generated primes: ") 37 | (display primes) 38 | (newline) 39 | -------------------------------------------------------------------------------- /examples/testcode.ss: -------------------------------------------------------------------------------- 1 | (define square (lambda (x) (* x x))) 2 | (define squarelist (lambda (l) (map square l))) 3 | (squarelist (quote (1 2))) 4 | 5 | ((lambda (l) (map (lambda (x) (* x x)) l)) '(100 200 300 400)) 6 | 7 | (define ifcarseq (lambda (list1 list2 fin) (if (= (car list1) (car list2)) (begin (display "true") fin) (begin (display "false") fin)))) 8 | 9 | (let countdown ((i 10)) (if (= i 0) "liftoff" (begin (display i)(newline) (countdown (- i 1))))) 10 | 11 | 12 | (define fac (lambda (n) 13 | (if (= 0 n) 14 | 1 15 | (* n (fac (- n 1)))))) 16 | 17 | 18 | (define fib (lambda (n) 19 | (if (< n 2) 20 | n 21 | (+ (fib (- n 1)) (fib (- n 2)))))) 22 | 23 | (define (fib-clever n) 24 | (define (fib-aux a b p q count) 25 | (cond ((= count 0) b) 26 | ((even? count) 27 | (fib-aux a 28 | b 29 | (+ (* p p) (* q q)) 30 | (+ (* q q) (* 2 p q)) 31 | (/ count 2))) 32 | (else 33 | (fib-aux (+ (* b q) (* a q) (* a p)) 34 | (+ (* b p) (* a q)) 35 | p 36 | q 37 | (- count 1))))) 38 | (fib-aux 1 0 0 1 n)) 39 | 40 | 41 | (let ((x 10) (y 20)) (+ x y)) 42 | 43 | (define x (lambda (x y) (x y 1))) 44 | (x (lambda (x y) (+ x y)) 2) 45 | 46 | (map (lambda (number) (+ 1 number)) (quote (1 2 3 4))) 47 | 48 | (foldr cons (quote ()) (quote (1 2 3 4))) 49 | 50 | (let loop ((i 0)) 51 | (if (not (= i 10)) 52 | (begin 53 | (display i)(display " squared = ")(display (* i i))(newline) 54 | (loop (+ i 1))))) 55 | 56 | (letrec ((factorial 57 | (lambda (n) 58 | (if (not (= n 0)) (* n (factorial (- n 1))) 59 | 1)))) 60 | (factorial 20)) 61 | 62 | 63 | (letrec ((is-even? (lambda (n) 64 | (or (= n 0) 65 | (is-odd? (- n 1))))) 66 | (is-odd? (lambda (n) 67 | (and (not (= n 0)) 68 | (is-even? (- n 1)))))) 69 | (is-odd? 10)) 70 | 71 | 72 | (letrec 73 | ((len (lambda (ls) 74 | (if (null? ls) 0 75 | (+ 1 (len (cdr ls))))))) 76 | (len '(1 2 3 5 6 7 8 9))) 77 | -------------------------------------------------------------------------------- /lib/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imphasing/schemin/e50011b2a265d053379f5d4e5fb91a736ed92510/lib/nunit.framework.dll -------------------------------------------------------------------------------- /schemin.nunit: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Schemin.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Schemin", "Schemin\Schemin.csproj", "{FEA08E52-2E71-4F05-8B98-F58FC8E5E64D}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScheminTests", "ScheminTests\ScheminTests.csproj", "{4BE3BDE5-81D7-42EA-8315-F12C00883AB3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|AnyCPU = Debug|AnyCPU 11 | Release|AnyCPU = Release|AnyCPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {FEA08E52-2E71-4F05-8B98-F58FC8E5E64D}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU 15 | {FEA08E52-2E71-4F05-8B98-F58FC8E5E64D}.Debug|AnyCPU.Build.0 = Debug|Any CPU 16 | {FEA08E52-2E71-4F05-8B98-F58FC8E5E64D}.Release|AnyCPU.ActiveCfg = Release|Any CPU 17 | {4BE3BDE5-81D7-42EA-8315-F12C00883AB3}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU 18 | {4BE3BDE5-81D7-42EA-8315-F12C00883AB3}.Debug|AnyCPU.Build.0 = Debug|Any CPU 19 | {4BE3BDE5-81D7-42EA-8315-F12C00883AB3}.Release|AnyCPU.ActiveCfg = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(SolutionProperties) = preSolution 22 | HideSolutionNode = FALSE 23 | EndGlobalSection 24 | EndGlobal 25 | -------------------------------------------------------------------------------- /src/Schemin/Assembly/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | using System; 29 | using System.Diagnostics; 30 | using System.Reflection; 31 | using System.Resources; 32 | using System.Security; 33 | using System.Security.Permissions; 34 | using System.Runtime.CompilerServices; 35 | using System.Runtime.InteropServices; 36 | 37 | [assembly: AssemblyTitle ("Schemin.exe")] 38 | [assembly: AssemblyVersion("0.0.1")] 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.AST/AtomFactory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.AST 29 | { 30 | using System; 31 | using System.Text; 32 | using System.Collections.Generic; 33 | using Schemin.AST; 34 | 35 | public static class AtomFactory 36 | { 37 | public static Dictionary atoms; 38 | 39 | static AtomFactory() 40 | { 41 | atoms = new Dictionary(); 42 | } 43 | 44 | public static ScheminAtom GetAtom(string name) 45 | { 46 | if (!atoms.ContainsKey(name)) 47 | { 48 | atoms.Add(name, new ScheminAtom(name)); 49 | } 50 | 51 | return atoms[name]; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.AST/IScheminNumeric.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.AST 29 | { 30 | using System.Numerics; 31 | 32 | public interface IScheminNumeric 33 | { 34 | decimal DecimalValue(); 35 | BigInteger IntegerValue(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.AST/IScheminType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.AST 29 | { 30 | public interface IScheminType 31 | { 32 | bool Equal(IScheminType type); 33 | bool Equivalent(IScheminType type); 34 | ScheminBool BoolValue(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.AST/ScheminAtom.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.AST 29 | { 30 | using Schemin.Evaluate; 31 | 32 | public class ScheminAtom : IScheminType 33 | { 34 | public string Name; 35 | public bool Closed = false; 36 | public Environment Closure = null; 37 | 38 | public ScheminAtom(string name) 39 | { 40 | this.Name = name; 41 | } 42 | 43 | public ScheminAtom(string name, Environment closure) 44 | { 45 | this.Name = name; 46 | this.Closure = closure; 47 | this.Closed = true; 48 | } 49 | 50 | public override string ToString() 51 | { 52 | return Name; 53 | } 54 | 55 | public bool Equivalent(IScheminType type) 56 | { 57 | if ((type as ScheminAtom) == null) 58 | { 59 | return false; 60 | } 61 | 62 | ScheminAtom temp = (ScheminAtom) type; 63 | if (this.Name == temp.Name) 64 | { 65 | return true; 66 | } 67 | 68 | return false; 69 | } 70 | 71 | public bool Equal(IScheminType type) 72 | { 73 | if (type == this) 74 | { 75 | return true; 76 | } 77 | 78 | return false; 79 | } 80 | 81 | public ScheminBool BoolValue() 82 | { 83 | return ScheminBool.True; 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.AST/ScheminContinuation.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.AST 29 | { 30 | using System; 31 | using Schemin.Evaluate; 32 | using System.Collections.Generic; 33 | using Environment = Schemin.Evaluate.Environment; 34 | 35 | public class ScheminContinuation : IScheminType 36 | { 37 | public Stack PreviousStack; 38 | 39 | public ScheminContinuation(Stack callStack) 40 | { 41 | PreviousStack = new Stack(callStack); 42 | } 43 | 44 | public override string ToString() 45 | { 46 | return ""; 47 | } 48 | 49 | public bool Equivalent(IScheminType type) 50 | { 51 | return Equal(type); 52 | } 53 | 54 | public bool Equal(IScheminType type) 55 | { 56 | if (type == this) 57 | { 58 | return true; 59 | } 60 | 61 | return false; 62 | } 63 | 64 | public ScheminBool BoolValue() 65 | { 66 | return ScheminBool.True; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.AST/ScheminDecimal.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.AST 29 | { 30 | using System.Numerics; 31 | 32 | public class ScheminDecimal : IScheminType, IScheminNumeric 33 | { 34 | public decimal Value; 35 | 36 | public ScheminDecimal(decimal value) 37 | { 38 | this.Value = value; 39 | } 40 | 41 | public override string ToString() 42 | { 43 | return Value.ToString(); 44 | } 45 | 46 | public bool Equivalent(IScheminType type) 47 | { 48 | if ((type as ScheminDecimal) == null) 49 | { 50 | return false; 51 | } 52 | 53 | ScheminDecimal temp = (ScheminDecimal) type; 54 | if (this.Value == temp.Value) 55 | { 56 | return true; 57 | } 58 | 59 | return false; 60 | } 61 | 62 | public bool Equal(IScheminType type) 63 | { 64 | if (type == this) 65 | { 66 | return true; 67 | } 68 | 69 | return false; 70 | } 71 | 72 | public decimal DecimalValue() 73 | { 74 | return this.Value; 75 | } 76 | 77 | public BigInteger IntegerValue() 78 | { 79 | return new BigInteger(this.Value); 80 | } 81 | 82 | public ScheminBool BoolValue() 83 | { 84 | return ScheminBool.True; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.AST/ScheminString.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.AST 29 | { 30 | public class ScheminString : IScheminType 31 | { 32 | public string Value; 33 | 34 | public ScheminString(string value) 35 | { 36 | this.Value = value; 37 | } 38 | 39 | public override string ToString() 40 | { 41 | return "\"" + Value + "\""; 42 | } 43 | 44 | public bool Equivalent(IScheminType type) 45 | { 46 | if ((type as ScheminString) == null) 47 | { 48 | return false; 49 | } 50 | 51 | ScheminString temp = (ScheminString) type; 52 | if (this.Value == temp.Value) 53 | { 54 | return true; 55 | } 56 | 57 | return false; 58 | } 59 | 60 | public bool Equal(IScheminType type) 61 | { 62 | if (type == this) 63 | { 64 | return true; 65 | } 66 | 67 | return false; 68 | } 69 | 70 | public ScheminBool BoolValue() 71 | { 72 | return ScheminBool.True; 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Evaluate/StackFrame.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Evaluate 29 | { 30 | using Schemin.AST; 31 | 32 | public class StackFrame 33 | { 34 | public IScheminType Evaluated; 35 | public IScheminType Unevaluated; 36 | public Environment CurrentEnv; 37 | 38 | public StackFrame(StackFrame original) 39 | { 40 | this.Evaluated = original.Evaluated; 41 | this.Unevaluated = original.Unevaluated; 42 | this.CurrentEnv = original.CurrentEnv; 43 | } 44 | 45 | public StackFrame() 46 | { 47 | this.Evaluated = new ScheminPair(); 48 | this.Unevaluated = new ScheminPair(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Evaluate/UnboundAtomException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Evaluate 29 | { 30 | using System; 31 | 32 | public class UnboundAtomException : Exception 33 | { 34 | public UnboundAtomException() : base() { } 35 | public UnboundAtomException(string message) : base(message) { } 36 | public UnboundAtomException(string message, System.Exception inner) : base(message, inner) { } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/BadArgumentsException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives 29 | { 30 | using System; 31 | 32 | public class BadArgumentsException : Exception 33 | { 34 | public BadArgumentsException() : base() { } 35 | public BadArgumentsException(string message) : base(message) { } 36 | public BadArgumentsException(string message, System.Exception inner) : base(message, inner) { } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Primitive.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives 29 | { 30 | using System; 31 | using Schemin.Evaluate; 32 | using Schemin.AST; 33 | using Environment = Schemin.Evaluate.Environment; 34 | 35 | public abstract class Primitive 36 | { 37 | public bool Rewriter = false; 38 | public abstract IScheminType Execute(Environment env, Evaluator eval, ScheminPair args); 39 | 40 | public virtual void CheckArguments(ScheminPair args) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/And.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class And : Primitive 34 | { 35 | public And() 36 | { 37 | base.Rewriter = true; 38 | } 39 | 40 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 41 | { 42 | ScheminPair nextCycle = new ScheminPair(); 43 | nextCycle = nextCycle.Append(new ScheminPrimitive("and")); 44 | 45 | if (args.Car.BoolValue() == ScheminBool.False) 46 | { 47 | return ScheminBool.False; 48 | } 49 | 50 | if (args.Length == 1) 51 | { 52 | return args.Car.BoolValue(); 53 | } 54 | else 55 | { 56 | bool first = true; 57 | foreach (IScheminType type in args) 58 | { 59 | if (!first) 60 | { 61 | nextCycle = nextCycle.Append(type); 62 | } 63 | 64 | first = false; 65 | } 66 | } 67 | 68 | return nextCycle; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Boolean.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Boolean : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType type = args.Car; 38 | 39 | if ((type as ScheminBool) != null) 40 | { 41 | return ScheminBool.True; 42 | } 43 | return ScheminBool.False; 44 | } 45 | 46 | public override void CheckArguments(ScheminPair args) 47 | { 48 | if (args.Length != 1) 49 | { 50 | throw new BadArgumentsException("expected 1 argument"); 51 | } 52 | 53 | return; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Char.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Char : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType type = args.Car; 38 | 39 | if ((type as ScheminChar) != null) 40 | { 41 | return ScheminBool.True; 42 | } 43 | 44 | return ScheminBool.False; 45 | } 46 | 47 | public override void CheckArguments(ScheminPair args) 48 | { 49 | if (args.Length != 1) 50 | { 51 | throw new BadArgumentsException("expected 1 argument"); 52 | } 53 | 54 | return; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/EOFObject.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class EOFObject : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType type = args.Car; 38 | 39 | if ((type as ScheminChar) != null) 40 | { 41 | ScheminChar chr = (ScheminChar) type; 42 | if (chr.EOF) 43 | { 44 | return ScheminBool.True; 45 | } 46 | } 47 | 48 | return ScheminBool.False; 49 | } 50 | 51 | public override void CheckArguments(ScheminPair args) 52 | { 53 | if (args.Length != 1) 54 | { 55 | throw new BadArgumentsException("expected 1 argument"); 56 | } 57 | 58 | return; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Eq.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Eq : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType first = args.Car; 38 | IScheminType second = args.ElementAt(1); 39 | 40 | return ScheminBool.GetValue(first.Equal(second)); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Eqv.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Eqv : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType first = args.Car; 38 | IScheminType second = args.ElementAt(1); 39 | 40 | return ScheminBool.GetValue(first.Equivalent(second)); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/InputPort.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class InputPort : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType type = args.Car; 38 | 39 | if ((type as ScheminPort) != null) 40 | { 41 | ScheminPort port = (ScheminPort) type; 42 | if (port.Type == ScheminPort.PortType.InputPort) 43 | { 44 | return ScheminBool.True; 45 | } 46 | } 47 | 48 | return ScheminBool.False; 49 | } 50 | 51 | public override void CheckArguments(ScheminPair args) 52 | { 53 | if (args.Length != 1) 54 | { 55 | throw new BadArgumentsException("expected 1 argument"); 56 | } 57 | 58 | return; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/List.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class List : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | if ((args.Car as ScheminPair) == null) 38 | { 39 | return ScheminBool.False; 40 | } 41 | 42 | ScheminPair listArg = (ScheminPair) args.Car; 43 | if (listArg.Proper) 44 | { 45 | return ScheminBool.True; 46 | } 47 | 48 | return ScheminBool.False; 49 | } 50 | 51 | public override void CheckArguments(ScheminPair args) 52 | { 53 | if (args.Length != 1) 54 | { 55 | throw new BadArgumentsException("expected 1 argument"); 56 | } 57 | 58 | return; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Null.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Null : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | if ((args.Car as ScheminPair) == null) 38 | { 39 | return ScheminBool.False; 40 | } 41 | 42 | ScheminPair listArg = (ScheminPair) args.Car; 43 | if (listArg.Empty) 44 | { 45 | return ScheminBool.True; 46 | } 47 | 48 | return ScheminBool.False; 49 | } 50 | 51 | public override void CheckArguments(ScheminPair args) 52 | { 53 | if (args.Length != 1) 54 | { 55 | throw new BadArgumentsException("expected 1 argument"); 56 | } 57 | 58 | return; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Number.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Number : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType type = args.Car; 38 | 39 | if ((type as ScheminInteger) != null || (type as ScheminDecimal) != null) 40 | { 41 | return ScheminBool.True; 42 | } 43 | 44 | return ScheminBool.False; 45 | } 46 | 47 | public override void CheckArguments(ScheminPair args) 48 | { 49 | if (args.Length != 1) 50 | { 51 | throw new BadArgumentsException("expected 1 argument"); 52 | } 53 | 54 | return; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Or.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Or : Primitive 34 | { 35 | public Or() 36 | { 37 | base.Rewriter = true; 38 | } 39 | 40 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 41 | { 42 | ScheminPair nextCycle = new ScheminPair(); 43 | nextCycle = nextCycle.Append(new ScheminPrimitive("or")); 44 | 45 | if (args.Car.BoolValue() == ScheminBool.True) 46 | { 47 | return ScheminBool.True; 48 | } 49 | 50 | if (args.Length == 1) 51 | { 52 | return args.Car.BoolValue(); 53 | } 54 | else 55 | { 56 | bool first = true; 57 | foreach (IScheminType type in args) 58 | { 59 | if (!first) 60 | { 61 | nextCycle = nextCycle.Append(type); 62 | } 63 | 64 | first = false; 65 | } 66 | } 67 | 68 | return nextCycle; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/OutputPort.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class OutputPort : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType type = args.Car; 38 | 39 | if ((type as ScheminPort) != null) 40 | { 41 | ScheminPort port = (ScheminPort) type; 42 | if (port.Type == ScheminPort.PortType.OutputPort) 43 | { 44 | return ScheminBool.True; 45 | } 46 | } 47 | 48 | return ScheminBool.False; 49 | } 50 | 51 | public override void CheckArguments(ScheminPair args) 52 | { 53 | if (args.Length != 1) 54 | { 55 | throw new BadArgumentsException("expected 1 argument"); 56 | } 57 | 58 | return; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Pair.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Pair : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType type = args.Car; 38 | 39 | if ((type as ScheminPair) != null) 40 | { 41 | ScheminPair temp = (ScheminPair) type; 42 | if (!temp.Empty) 43 | { 44 | return ScheminBool.True; 45 | } 46 | } 47 | 48 | return ScheminBool.False; 49 | } 50 | 51 | public override void CheckArguments(ScheminPair args) 52 | { 53 | if (args.Length != 1) 54 | { 55 | throw new BadArgumentsException("expected 1 argument"); 56 | } 57 | 58 | return; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Port.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Port : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType type = args.Car; 38 | 39 | if ((type as ScheminPort) != null) 40 | { 41 | return ScheminBool.True; 42 | } 43 | 44 | return ScheminBool.False; 45 | } 46 | 47 | public override void CheckArguments(ScheminPair args) 48 | { 49 | if (args.Length != 1) 50 | { 51 | throw new BadArgumentsException("expected 1 argument"); 52 | } 53 | 54 | return; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Procedure.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Procedure : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType type = args.Car; 38 | 39 | if ((type as ScheminPrimitive) != null || (type as ScheminLambda) != null 40 | || (type as ScheminContinuation) != null || (type as ScheminRewriter) != null) 41 | { 42 | return ScheminBool.True; 43 | } 44 | 45 | return ScheminBool.False; 46 | } 47 | 48 | public override void CheckArguments(ScheminPair args) 49 | { 50 | if (args.Length != 1) 51 | { 52 | throw new BadArgumentsException("expected 1 argument"); 53 | } 54 | 55 | return; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/String.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class String : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType type = args.Car; 38 | 39 | if ((type as ScheminString) != null) 40 | { 41 | return ScheminBool.True; 42 | } 43 | 44 | return ScheminBool.False; 45 | } 46 | 47 | public override void CheckArguments(ScheminPair args) 48 | { 49 | if (args.Length != 1) 50 | { 51 | throw new BadArgumentsException("expected 1 argument"); 52 | } 53 | 54 | return; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Symbol.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Symbol : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType type = args.Car; 38 | 39 | if ((type as ScheminAtom) != null) 40 | { 41 | return ScheminBool.True; 42 | } 43 | return ScheminBool.False; 44 | } 45 | 46 | public override void CheckArguments(ScheminPair args) 47 | { 48 | if (args.Length != 1) 49 | { 50 | throw new BadArgumentsException("expected 1 argument"); 51 | } 52 | 53 | return; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.BooleanOperations/Vector.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.BooleanOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | public class Vector : Primitive 33 | { 34 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 35 | { 36 | IScheminType type = args.Car; 37 | 38 | if ((type as ScheminVector) != null) 39 | { 40 | return ScheminBool.True; 41 | } 42 | 43 | return ScheminBool.False; 44 | } 45 | 46 | public override void CheckArguments(ScheminPair args) 47 | { 48 | if (args.Length != 1) 49 | { 50 | throw new BadArgumentsException("expected 1 argument"); 51 | } 52 | 53 | return; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharAlphabetic.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class CharAlphabetic : Primitive 36 | { 37 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 38 | { 39 | ScheminChar chr = (ScheminChar) args.Car; 40 | 41 | if (Char.IsLetter(chr.Value)) 42 | { 43 | return ScheminBool.True; 44 | } 45 | 46 | return ScheminBool.False; 47 | } 48 | 49 | public override void CheckArguments(ScheminPair args) 50 | { 51 | IScheminType first = args.Car; 52 | 53 | if (args.Length != 1) 54 | { 55 | throw new BadArgumentsException("expected 1 argument"); 56 | } 57 | 58 | if ((first as ScheminChar) == null) 59 | { 60 | throw new BadArgumentsException("argument must be a char"); 61 | } 62 | 63 | return; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharDowncase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class CharDowncase : Primitive 36 | { 37 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 38 | { 39 | ScheminChar chr = (ScheminChar) args.Car; 40 | return new ScheminChar(Char.ToLowerInvariant(chr.Value)); 41 | } 42 | 43 | public override void CheckArguments(ScheminPair args) 44 | { 45 | IScheminType first = args.Car; 46 | 47 | if (args.Length != 1) 48 | { 49 | throw new BadArgumentsException("expected 1 argument"); 50 | } 51 | 52 | if ((first as ScheminChar) == null) 53 | { 54 | throw new BadArgumentsException("argument must be a char"); 55 | } 56 | 57 | return; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharEquals.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | public class CharEquals : Primitive 33 | { 34 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 35 | { 36 | ScheminChar first = (ScheminChar) args.Car; 37 | ScheminChar second = (ScheminChar) args.ElementAt(1); 38 | 39 | if (first.Equivalent(second)) 40 | { 41 | return ScheminBool.True; 42 | } 43 | 44 | return ScheminBool.False; 45 | } 46 | 47 | public override void CheckArguments(ScheminPair args) 48 | { 49 | IScheminType first = args.Car; 50 | IScheminType second = args.ElementAt(1); 51 | 52 | if (args.Length != 2) 53 | { 54 | throw new BadArgumentsException("expected 2 arguments"); 55 | } 56 | 57 | if ((first as ScheminChar) == null || (second as ScheminChar) == null) 58 | { 59 | throw new BadArgumentsException("arguments must be chars"); 60 | } 61 | 62 | return; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharGreaterThan.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class CharGreaterThan : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminChar first = (ScheminChar) args.Car; 38 | ScheminChar second = (ScheminChar) args.ElementAt(1); 39 | 40 | int result = first.Value.CompareTo(second.Value); 41 | 42 | if (result < 0) 43 | { 44 | return ScheminBool.True; 45 | } 46 | 47 | return ScheminBool.False; 48 | } 49 | 50 | public override void CheckArguments(ScheminPair args) 51 | { 52 | IScheminType first = args.Car; 53 | IScheminType second = args.ElementAt(1); 54 | 55 | if (args.Length != 2) 56 | { 57 | throw new BadArgumentsException("expected 2 arguments"); 58 | } 59 | 60 | if ((first as ScheminChar) == null || (second as ScheminChar) == null) 61 | { 62 | throw new BadArgumentsException("arguments must be chars"); 63 | } 64 | 65 | return; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharGreaterThanOr.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class CharGreaterThanOr : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminChar first = (ScheminChar) args.Car; 38 | ScheminChar second = (ScheminChar) args.ElementAt(1); 39 | 40 | int result = first.Value.CompareTo(second.Value); 41 | 42 | if (result <= 0) 43 | { 44 | return ScheminBool.True; 45 | } 46 | 47 | return ScheminBool.False; 48 | } 49 | 50 | public override void CheckArguments(ScheminPair args) 51 | { 52 | IScheminType first = args.Car; 53 | IScheminType second = args.ElementAt(1); 54 | 55 | if (args.Length != 2) 56 | { 57 | throw new BadArgumentsException("expected 2 arguments"); 58 | } 59 | 60 | if ((first as ScheminChar) == null || (second as ScheminChar) == null) 61 | { 62 | throw new BadArgumentsException("arguments must be chars"); 63 | } 64 | 65 | return; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharInteger.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class CharInteger : Primitive 36 | { 37 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 38 | { 39 | ScheminChar chr = (ScheminChar) args.Car; 40 | 41 | int result = Convert.ToInt32(chr.Value); 42 | return new ScheminInteger(result); 43 | } 44 | 45 | public override void CheckArguments(ScheminPair args) 46 | { 47 | IScheminType first = args.Car; 48 | 49 | if (args.Length != 1) 50 | { 51 | throw new BadArgumentsException("expected 1 argument"); 52 | } 53 | 54 | if ((first as ScheminChar) == null) 55 | { 56 | throw new BadArgumentsException("argument must be a char"); 57 | } 58 | 59 | return; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharLessThan.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class CharLessThan : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminChar first = (ScheminChar) args.Car; 38 | ScheminChar second = (ScheminChar) args.ElementAt(1); 39 | 40 | int result = first.Value.CompareTo(second.Value); 41 | 42 | if (result > 0) 43 | { 44 | return ScheminBool.True; 45 | } 46 | 47 | return ScheminBool.False; 48 | } 49 | 50 | public override void CheckArguments(ScheminPair args) 51 | { 52 | IScheminType first = args.Car; 53 | IScheminType second = args.ElementAt(1); 54 | 55 | if (args.Length != 2) 56 | { 57 | throw new BadArgumentsException("expected 2 arguments"); 58 | } 59 | 60 | if ((first as ScheminChar) == null || (second as ScheminChar) == null) 61 | { 62 | throw new BadArgumentsException("arguments must be chars"); 63 | } 64 | 65 | return; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharLessThanOr.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class CharLessThanOr : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminChar first = (ScheminChar) args.Car; 38 | ScheminChar second = (ScheminChar) args.ElementAt(1); 39 | 40 | int result = first.Value.CompareTo(second.Value); 41 | 42 | if (result <= 0) 43 | { 44 | return ScheminBool.True; 45 | } 46 | 47 | return ScheminBool.False; 48 | } 49 | 50 | public override void CheckArguments(ScheminPair args) 51 | { 52 | IScheminType first = args.Car; 53 | IScheminType second = args.ElementAt(1); 54 | 55 | if (args.Length != 2) 56 | { 57 | throw new BadArgumentsException("expected 2 arguments"); 58 | } 59 | 60 | if ((first as ScheminChar) == null || (second as ScheminChar) == null) 61 | { 62 | throw new BadArgumentsException("arguments must be chars"); 63 | } 64 | 65 | return; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharLowerCase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class CharLowerCase : Primitive 36 | { 37 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 38 | { 39 | ScheminChar chr = (ScheminChar) args.Car; 40 | 41 | if (Char.IsLower(chr.Value)) 42 | { 43 | return ScheminBool.True; 44 | } 45 | 46 | return ScheminBool.False; 47 | } 48 | 49 | public override void CheckArguments(ScheminPair args) 50 | { 51 | IScheminType first = args.Car; 52 | 53 | if (args.Length != 1) 54 | { 55 | throw new BadArgumentsException("expected 1 argument"); 56 | } 57 | 58 | if ((first as ScheminChar) == null) 59 | { 60 | throw new BadArgumentsException("argument must be a char"); 61 | } 62 | 63 | return; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharNumeric.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class CharNumeric : Primitive 36 | { 37 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 38 | { 39 | ScheminChar chr = (ScheminChar) args.Car; 40 | 41 | if (Char.IsNumber(chr.Value)) 42 | { 43 | return ScheminBool.True; 44 | } 45 | 46 | return ScheminBool.False; 47 | } 48 | 49 | public override void CheckArguments(ScheminPair args) 50 | { 51 | IScheminType first = args.Car; 52 | 53 | if (args.Length != 1) 54 | { 55 | throw new BadArgumentsException("expected 1 argument"); 56 | } 57 | 58 | if ((first as ScheminChar) == null) 59 | { 60 | throw new BadArgumentsException("argument must be a char"); 61 | } 62 | 63 | return; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharUpcase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class CharUpcase : Primitive 36 | { 37 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 38 | { 39 | ScheminChar chr = (ScheminChar) args.Car; 40 | return new ScheminChar(Char.ToUpperInvariant(chr.Value)); 41 | } 42 | 43 | public override void CheckArguments(ScheminPair args) 44 | { 45 | IScheminType first = args.Car; 46 | 47 | if (args.Length != 1) 48 | { 49 | throw new BadArgumentsException("expected 1 argument"); 50 | } 51 | 52 | if ((first as ScheminChar) == null) 53 | { 54 | throw new BadArgumentsException("argument must be a char"); 55 | } 56 | 57 | return; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharUpperCase.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class CharUpperCase : Primitive 36 | { 37 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 38 | { 39 | ScheminChar chr = (ScheminChar) args.Car; 40 | 41 | if (Char.IsUpper(chr.Value)) 42 | { 43 | return ScheminBool.True; 44 | } 45 | 46 | return ScheminBool.False; 47 | } 48 | 49 | public override void CheckArguments(ScheminPair args) 50 | { 51 | IScheminType first = args.Car; 52 | 53 | if (args.Length != 1) 54 | { 55 | throw new BadArgumentsException("expected 1 argument"); 56 | } 57 | 58 | if ((first as ScheminChar) == null) 59 | { 60 | throw new BadArgumentsException("argument must be a char"); 61 | } 62 | 63 | return; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/CharWhitespace.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class CharWhitespace : Primitive 36 | { 37 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 38 | { 39 | ScheminChar chr = (ScheminChar) args.Car; 40 | 41 | if (Char.IsWhiteSpace(chr.Value)) 42 | { 43 | return ScheminBool.True; 44 | } 45 | 46 | return ScheminBool.False; 47 | } 48 | 49 | public override void CheckArguments(ScheminPair args) 50 | { 51 | IScheminType first = args.Car; 52 | 53 | if (args.Length != 1) 54 | { 55 | throw new BadArgumentsException("expected 1 argument"); 56 | } 57 | 58 | if ((first as ScheminChar) == null) 59 | { 60 | throw new BadArgumentsException("argument must be a char"); 61 | } 62 | 63 | return; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.CharOperations/IntegerChar.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.CharOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class IntegerChar : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminInteger num = (ScheminInteger) args.Car; 38 | 39 | return new ScheminChar((char) num.Value); 40 | } 41 | 42 | public override void CheckArguments(ScheminPair args) 43 | { 44 | IScheminType first = args.Car; 45 | 46 | if (args.Length != 1) 47 | { 48 | throw new BadArgumentsException("expected 1 argument"); 49 | } 50 | 51 | if ((first as ScheminInteger) == null) 52 | { 53 | throw new BadArgumentsException("argument must be an integer"); 54 | } 55 | 56 | return; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.GeneralOperations/Begin.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.GeneralOperations 29 | { 30 | using System.Linq; 31 | using Schemin.Evaluate; 32 | using Schemin.AST; 33 | 34 | public class Begin : Primitive 35 | { 36 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 37 | { 38 | if (args.Length > 0) 39 | { 40 | return args.Last(); 41 | } 42 | else 43 | { 44 | return new ScheminPair(); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.GeneralOperations/CallCC.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.GeneralOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class CallCC : Primitive 34 | { 35 | public CallCC() 36 | { 37 | base.Rewriter = true; 38 | } 39 | 40 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 41 | { 42 | ScheminPair applied = new ScheminPair(); 43 | 44 | applied = applied.Append(args.Car); 45 | applied = applied.Append(new ScheminContinuation(eval.Stack)); 46 | 47 | return applied; 48 | } 49 | 50 | public override void CheckArguments(ScheminPair args) 51 | { 52 | IScheminType first = args.Car; 53 | 54 | if (args.Length != 1) 55 | { 56 | throw new BadArgumentsException("expected 1 argument"); 57 | } 58 | 59 | if ((first as ScheminPrimitive) == null && (first as ScheminLambda) == null 60 | && (first as ScheminContinuation) == null && (first as ScheminRewriter) == null) 61 | { 62 | throw new BadArgumentsException("first argument must be a procedure"); 63 | } 64 | 65 | return; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.GeneralOperations/DumpEnv.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.GeneralOperations 29 | { 30 | using System; 31 | using System.Collections.Generic; 32 | using Environment = Schemin.Evaluate.Environment; 33 | using Schemin.Evaluate; 34 | using Schemin.AST; 35 | 36 | public class DumpEnv : Primitive 37 | { 38 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 39 | { 40 | ScheminPair bindings = new ScheminPair(); 41 | 42 | foreach (KeyValuePair kvp in env.bindings) 43 | { 44 | var binding = new ScheminPair(AtomFactory.GetAtom(kvp.Key)); 45 | binding = binding.Append(kvp.Value); 46 | 47 | bindings = bindings.Append(binding); 48 | } 49 | 50 | return bindings; 51 | } 52 | 53 | public override void CheckArguments(ScheminPair args) 54 | { 55 | if (args.Length != 0) 56 | { 57 | throw new BadArgumentsException("expected 0 arguments"); 58 | } 59 | 60 | return; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.GeneralOperations/Eval.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.GeneralOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Eval : Primitive 34 | { 35 | public Eval() 36 | { 37 | base.Rewriter = true; 38 | } 39 | 40 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 41 | { 42 | return eval.interpreter.macroExpander.ExpandAll(args.Car); 43 | } 44 | 45 | public override void CheckArguments(ScheminPair args) 46 | { 47 | if (args.Length != 1) 48 | { 49 | throw new BadArgumentsException("expected 1 argument"); 50 | } 51 | 52 | return; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.GeneralOperations/Expand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.GeneralOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Expand : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | return eval.interpreter.macroExpander.ExpandAll(args.Car); 38 | } 39 | 40 | public override void CheckArguments(ScheminPair args) 41 | { 42 | if (args.Length != 1) 43 | { 44 | throw new BadArgumentsException("expected 1 argument"); 45 | } 46 | 47 | return; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.GeneralOperations/GenSym.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.GeneralOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class GenSym : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType argument = args.Car; 38 | if ((argument as ScheminInteger) != null) 39 | { 40 | ScheminInteger newSeed = (ScheminInteger) argument; 41 | eval.GenSymSeed = (int) newSeed.IntegerValue(); 42 | } 43 | else if ((argument as ScheminString) != null) 44 | { 45 | ScheminString newPrefix = (ScheminString) argument; 46 | eval.GenSymPrefix = newPrefix.Value; 47 | } 48 | 49 | string symbolName = eval.GenSymPrefix + eval.GenSymSeed.ToString(); 50 | eval.GenSymSeed++; 51 | 52 | ScheminAtom gen = AtomFactory.GetAtom(symbolName); 53 | return gen; 54 | } 55 | 56 | public override void CheckArguments(ScheminPair args) 57 | { 58 | if (args.Length > 1) 59 | { 60 | throw new BadArgumentsException("expected 1 or 0 arguments"); 61 | } 62 | 63 | return; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.GeneralOperations/If.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.GeneralOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class If : Primitive 34 | { 35 | public If() 36 | { 37 | base.Rewriter = true; 38 | } 39 | 40 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 41 | { 42 | ScheminBool condition = args.Car.BoolValue(); 43 | IScheminType then = args.ElementAt(1); 44 | IScheminType otherwise = new ScheminPair(); 45 | 46 | if (args.Length > 2) 47 | otherwise = args.ElementAt(2); 48 | 49 | if (condition.Value) 50 | { 51 | return then; 52 | } 53 | else 54 | { 55 | return otherwise; 56 | } 57 | } 58 | 59 | public override void CheckArguments(ScheminPair args) 60 | { 61 | if (args.Length < 2 || args.Length > 3) 62 | { 63 | throw new BadArgumentsException("expected 2 or 3 arguments"); 64 | } 65 | 66 | return; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.GeneralOperations/Lambda.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.GeneralOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Lambda : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminLambda lam = new ScheminLambda(args, env); 38 | return lam; 39 | } 40 | 41 | public override void CheckArguments(ScheminPair args) 42 | { 43 | if (args.Length < 2) 44 | { 45 | throw new BadArgumentsException("expected at least 2 arguments"); 46 | } 47 | 48 | return; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.GeneralOperations/LetStar.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.GeneralOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class LetStar : Primitive 34 | { 35 | public LetStar() 36 | { 37 | base.Rewriter = true; 38 | } 39 | 40 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 41 | { 42 | ScheminPair bindings = (ScheminPair) args.Car; 43 | IScheminType expression = args.ElementAt(1); 44 | 45 | ScheminPair first = new ScheminPair(); 46 | ScheminPair firstBinding = new ScheminPair(bindings.Car); 47 | 48 | first = first.Append(new ScheminPrimitive("let")); 49 | first = first.Append(firstBinding); 50 | 51 | if (bindings.Cdr != null) 52 | { 53 | ScheminPair nextLet = new ScheminPair(bindings.Cdr); 54 | nextLet = nextLet.Cons(new ScheminPrimitive("let*")); 55 | nextLet = nextLet.Append(expression); 56 | 57 | first = first.Append(nextLet); 58 | } 59 | else 60 | { 61 | first = first.Append(expression); 62 | } 63 | 64 | return first; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.GeneralOperations/Quote.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.GeneralOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Quote : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType arg = args.Car; 38 | return arg; 39 | } 40 | 41 | public override void CheckArguments(ScheminPair args) 42 | { 43 | if (args.Length != 1) 44 | { 45 | throw new BadArgumentsException("expected 1 or 0 arguments"); 46 | } 47 | 48 | return; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.ListOperations/Append.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.ListOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class Append : Primitive 36 | { 37 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 38 | { 39 | ScheminPair appended = new ScheminPair(); 40 | 41 | foreach (IScheminType type in args) 42 | { 43 | if ((type as ScheminPair) != null) 44 | { 45 | ScheminPair temp = (ScheminPair) type; 46 | 47 | if (temp.Empty) 48 | { 49 | continue; 50 | } 51 | 52 | foreach (IScheminType subType in temp) 53 | { 54 | appended = appended.Append(subType); 55 | } 56 | } 57 | else 58 | { 59 | throw new BadArgumentsException("all arguments must be lists"); 60 | } 61 | } 62 | 63 | return appended; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.ListOperations/Car.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.ListOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Car : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPair listArg = (ScheminPair) args.Car; 38 | return listArg.Car; 39 | } 40 | 41 | public override void CheckArguments(ScheminPair args) 42 | { 43 | IScheminType first = args.Car; 44 | 45 | if (args.Length != 1) 46 | { 47 | throw new BadArgumentsException("expected 1 argument"); 48 | } 49 | 50 | if ((first as ScheminPair) == null) 51 | { 52 | throw new BadArgumentsException("argument must be a list"); 53 | } 54 | 55 | return; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.ListOperations/Cdr.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.ListOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Cdr : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPair listArg = (ScheminPair) args.Car; 38 | if (listArg.Cdr == null) 39 | { 40 | return new ScheminPair(); 41 | } 42 | else 43 | { 44 | if (!listArg.Proper) 45 | return listArg.Cdr; 46 | 47 | return listArg.ListCdr(); 48 | } 49 | } 50 | 51 | public override void CheckArguments(ScheminPair args) 52 | { 53 | IScheminType first = args.Car; 54 | 55 | if (args.Length != 1) 56 | { 57 | throw new BadArgumentsException("expected 1 argument"); 58 | } 59 | 60 | if ((first as ScheminPair) == null) 61 | { 62 | throw new BadArgumentsException("argument must be a list"); 63 | } 64 | 65 | return; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.ListOperations/Cons.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.ListOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Cons : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminType head = args.Car; 38 | IScheminType rest = args.ElementAt(1); 39 | 40 | if ((rest as ScheminPair) != null && ((ScheminPair) rest).Proper) 41 | { 42 | ScheminPair temp = (ScheminPair) rest; 43 | 44 | if (temp.Empty) 45 | { 46 | return new ScheminPair(head); 47 | } 48 | else 49 | { 50 | ScheminPair consd = new ScheminPair(head); 51 | 52 | foreach (IScheminType type in temp) 53 | { 54 | consd = consd.Append(type); 55 | } 56 | 57 | return consd; 58 | } 59 | } 60 | 61 | return new ScheminPair(head, rest); 62 | } 63 | 64 | public override void CheckArguments(ScheminPair args) 65 | { 66 | if (args.Length != 2) 67 | { 68 | throw new BadArgumentsException("expected 2 arguments"); 69 | } 70 | 71 | return; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.ListOperations/Length.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.ListOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Length : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPair listArg = (ScheminPair) args.Car; 38 | return new ScheminInteger(listArg.Length); 39 | } 40 | 41 | public override void CheckArguments(ScheminPair args) 42 | { 43 | IScheminType first = args.Car; 44 | 45 | if (args.Length != 1) 46 | { 47 | throw new BadArgumentsException("expected 1 argument"); 48 | } 49 | 50 | if ((first as ScheminPair) == null) 51 | { 52 | throw new BadArgumentsException("argument must be a list"); 53 | } 54 | 55 | return; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.ListOperations/List.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.ListOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class List : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPair ret = new ScheminPair(); 38 | 39 | if ((args as ScheminPair) != null) 40 | { 41 | ScheminPair temp = (ScheminPair) args; 42 | foreach (IScheminType type in temp) 43 | { 44 | ret = ret.Append(type); 45 | } 46 | } 47 | else 48 | { 49 | ret = ret.Append(args); 50 | } 51 | 52 | return ret; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.ListOperations/Reverse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.ListOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Reverse : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPair listArg = (ScheminPair) args.Car; 38 | ScheminPair reversed = new ScheminPair(); 39 | foreach (IScheminType type in listArg) 40 | { 41 | reversed.Cons(type); 42 | } 43 | 44 | return reversed; 45 | } 46 | 47 | public override void CheckArguments(ScheminPair args) 48 | { 49 | IScheminType first = args.Car; 50 | 51 | if (args.Length != 1) 52 | { 53 | throw new BadArgumentsException("expected 1 argument"); 54 | } 55 | 56 | if ((first as ScheminPair) == null) 57 | { 58 | throw new BadArgumentsException("argument must be a list"); 59 | } 60 | 61 | return; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.ListOperations/SetCar.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.ListOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class SetCar : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPair pair = (ScheminPair) args.Car; 38 | IScheminType val = args.ElementAt(1); 39 | 40 | pair.Car = val; 41 | return new ScheminPair(); 42 | } 43 | 44 | public override void CheckArguments(ScheminPair args) 45 | { 46 | IScheminType first = args.Car; 47 | 48 | if (args.Length != 2) 49 | { 50 | throw new BadArgumentsException("expected 2 arguments"); 51 | } 52 | 53 | if ((first as ScheminPair) == null) 54 | { 55 | throw new BadArgumentsException("first argument must be a list"); 56 | } 57 | 58 | return; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.ListOperations/SetCdr.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.ListOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class SetCdr : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPair pair = (ScheminPair) args.Car; 38 | IScheminType val = args.ElementAt(1); 39 | 40 | pair.Cdr = val; 41 | return new ScheminPair(); 42 | } 43 | 44 | public override void CheckArguments(ScheminPair args) 45 | { 46 | IScheminType first = args.Car; 47 | 48 | if (args.Length != 2) 49 | { 50 | throw new BadArgumentsException("expected 2 arguments"); 51 | } 52 | 53 | if ((first as ScheminPair) == null) 54 | { 55 | throw new BadArgumentsException("first argument must be a list"); 56 | } 57 | 58 | return; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.NumericOperations/NumberString.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.NumericOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class NumberString : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | IScheminNumeric num = (IScheminNumeric) args.Car; 38 | 39 | if ((num as ScheminDecimal) != null) 40 | { 41 | return new ScheminString(num.DecimalValue().ToString()); 42 | } 43 | else 44 | { 45 | return new ScheminString(num.IntegerValue().ToString()); 46 | } 47 | } 48 | 49 | public override void CheckArguments(ScheminPair args) 50 | { 51 | IScheminType first = args.Car; 52 | 53 | if (args.Length != 1) 54 | throw new BadArgumentsException("expected 1 argument"); 55 | 56 | if ((first as IScheminNumeric) == null) 57 | throw new BadArgumentsException("argument must be numerical"); 58 | 59 | return; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.PortOperations/ClosePort.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.PortOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class ClosePort : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPort toClose = (ScheminPort) args.Car; 38 | if (toClose.Type == ScheminPort.PortType.InputPort) 39 | { 40 | toClose.InputStream.Close(); 41 | } 42 | else 43 | { 44 | toClose.OutputStream.Close(); 45 | } 46 | toClose.Closed = true; 47 | return new ScheminPair(); 48 | } 49 | 50 | public override void CheckArguments(ScheminPair args) 51 | { 52 | IScheminType first = args.Car; 53 | 54 | if (args.Length != 1) 55 | { 56 | throw new BadArgumentsException("expected 1 argument"); 57 | } 58 | 59 | if ((first as ScheminPort) == null) 60 | { 61 | throw new BadArgumentsException("argument must be a port"); 62 | } 63 | 64 | return; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.PortOperations/CurrentInputPort.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.PortOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class CurrentInputPort : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | return eval.CurrentInputPort; 38 | } 39 | 40 | public override void CheckArguments(ScheminPair args) 41 | { 42 | if (args.Length != 0) 43 | { 44 | throw new BadArgumentsException("expected 0 arguments"); 45 | } 46 | 47 | return; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.PortOperations/CurrentOutputPort.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.PortOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class CurrentOutputPort : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | return eval.CurrentOutputPort; 38 | } 39 | 40 | public override void CheckArguments(ScheminPair args) 41 | { 42 | if (args.Length != 0) 43 | { 44 | throw new BadArgumentsException("expected 0 arguments"); 45 | } 46 | 47 | return; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.PortOperations/Newline.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.PortOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Newline : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPort writeTo = eval.CurrentOutputPort; 38 | 39 | if (args.Length > 0) 40 | { 41 | writeTo = (ScheminPort) args.Car; 42 | } 43 | 44 | writeTo.OutputStream.Write(System.Environment.NewLine); 45 | writeTo.OutputStream.Flush(); 46 | 47 | return new ScheminPair(); 48 | } 49 | 50 | public override void CheckArguments(ScheminPair args) 51 | { 52 | if (args.Length > 1) 53 | { 54 | throw new BadArgumentsException("expected 1 or 0 arguments"); 55 | } 56 | 57 | if (args.Length == 1) 58 | { 59 | IScheminType port = args.Car; 60 | if ((port as ScheminPort) == null) 61 | { 62 | throw new BadArgumentsException("second argument must be a port"); 63 | } 64 | } 65 | 66 | return; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.PortOperations/OpenInputFile.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.PortOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using System.IO; 33 | using Schemin.Evaluate; 34 | using Schemin.AST; 35 | 36 | public class OpenInputFile : Primitive 37 | { 38 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 39 | { 40 | ScheminString filename = (ScheminString) args.Car; 41 | string baseDir = AppDomain.CurrentDomain.BaseDirectory; 42 | FileStream fs = File.OpenRead(baseDir + Path.DirectorySeparatorChar + filename.Value); 43 | ScheminPort filePort = new ScheminPort(fs, ScheminPort.PortType.InputPort); 44 | 45 | return filePort; 46 | } 47 | 48 | public override void CheckArguments(ScheminPair args) 49 | { 50 | IScheminType first = args.Car; 51 | 52 | if (args.Length != 1) 53 | { 54 | throw new BadArgumentsException("expected 1 argument"); 55 | } 56 | 57 | if ((first as ScheminString) == null) 58 | { 59 | throw new BadArgumentsException("argument must be a string"); 60 | } 61 | 62 | return; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.PortOperations/PortClosed.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.PortOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class PortClosed : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPort toCheck = (ScheminPort) args.Car; 38 | if (toCheck.Closed) 39 | { 40 | return ScheminBool.True; 41 | } 42 | 43 | return ScheminBool.False; 44 | } 45 | 46 | public override void CheckArguments(ScheminPair args) 47 | { 48 | IScheminType first = args.Car; 49 | 50 | if (args.Length != 1) 51 | { 52 | throw new BadArgumentsException("expected 1 argument"); 53 | } 54 | 55 | if ((first as ScheminPort) == null) 56 | { 57 | throw new BadArgumentsException("argument must be a port"); 58 | } 59 | 60 | return; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.PortOperations/SetCurrentInputPort.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.PortOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | public class SetCurrentInputPort : Primitive 33 | { 34 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 35 | { 36 | ScheminPort inputPort = (ScheminPort) args.Car; 37 | eval.CurrentInputPort = inputPort; 38 | return new ScheminPair(); 39 | } 40 | 41 | public override void CheckArguments(ScheminPair args) 42 | { 43 | IScheminType first = args.Car; 44 | 45 | if (args.Length != 1) 46 | { 47 | throw new BadArgumentsException("expected 1 argument"); 48 | } 49 | 50 | if ((first as ScheminPort) == null) 51 | { 52 | throw new BadArgumentsException("argument must be a port"); 53 | } 54 | 55 | return; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.PortOperations/SetCurrentOutputPort.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.PortOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class SetCurrentOutputPort : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPort outputPort = (ScheminPort) args.Car; 38 | eval.CurrentOutputPort = outputPort; 39 | return new ScheminPair(); 40 | } 41 | 42 | public override void CheckArguments(ScheminPair args) 43 | { 44 | IScheminType first = args.Car; 45 | 46 | if (args.Length != 1) 47 | { 48 | throw new BadArgumentsException("expected 1 argument"); 49 | } 50 | 51 | if ((first as ScheminPort) == null) 52 | { 53 | throw new BadArgumentsException("argument must be a port"); 54 | } 55 | 56 | return; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.StringOperations/StringAppend.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.StringOperations 29 | { 30 | using System.Text; 31 | using Schemin.Evaluate; 32 | using Schemin.AST; 33 | 34 | public class StringAppend : Primitive 35 | { 36 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 37 | { 38 | ScheminPair strs = args; 39 | StringBuilder sb = new StringBuilder(); 40 | 41 | foreach (IScheminType type in strs) 42 | { 43 | ScheminString str = (ScheminString) type; 44 | sb.Append(str.Value); 45 | } 46 | 47 | return new ScheminString(sb.ToString()); 48 | } 49 | 50 | public override void CheckArguments(ScheminPair args) 51 | { 52 | foreach (IScheminType type in args) 53 | { 54 | if ((type as ScheminString) == null) 55 | throw new BadArgumentsException("all arguments must be strings"); 56 | } 57 | 58 | return; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.StringOperations/StringLength.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.StringOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | public class StringLength : Primitive 33 | { 34 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 35 | { 36 | ScheminString str = (ScheminString) args.Car; 37 | ScheminInteger len = new ScheminInteger(str.Value.Length); 38 | return len; 39 | } 40 | 41 | public override void CheckArguments(ScheminPair args) 42 | { 43 | IScheminType first = args.Car; 44 | 45 | if (args.Length != 1) 46 | { 47 | throw new BadArgumentsException("expected 1 argument"); 48 | } 49 | 50 | if ((first as ScheminString) == null) 51 | { 52 | throw new BadArgumentsException("first argument must be a string"); 53 | } 54 | 55 | return; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.StringOperations/StringList.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.StringOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class StringList : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminString str = (ScheminString) args.Car; 38 | 39 | ScheminPair pair = new ScheminPair(); 40 | foreach (char c in str.Value) 41 | { 42 | pair = pair.Append(new ScheminChar(c)); 43 | } 44 | 45 | return pair; 46 | } 47 | 48 | public override void CheckArguments(ScheminPair args) 49 | { 50 | IScheminType first = args.Car; 51 | 52 | if (args.Length != 1) 53 | { 54 | throw new BadArgumentsException("expected 1 argument"); 55 | } 56 | 57 | if ((first as ScheminString) == null) 58 | { 59 | throw new BadArgumentsException("first argument must be a string"); 60 | } 61 | 62 | return; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.SymbolOperations/CreateClosedSymbol.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.SymbolOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class CreateClosedSymbol : Primitive 36 | { 37 | // Creates a symbol with a closure to evaluate in, instead of being evaluated in the current env 38 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 39 | { 40 | ScheminAtom sym = (ScheminAtom) args.Car; 41 | return new ScheminAtom(sym.Name, env); 42 | } 43 | 44 | public override void CheckArguments(ScheminPair args) 45 | { 46 | IScheminType first = args.Car; 47 | 48 | if (args.Length != 1) 49 | { 50 | throw new BadArgumentsException("expected 1 argument"); 51 | } 52 | 53 | if ((first as ScheminAtom) == null) 54 | { 55 | throw new BadArgumentsException("argument must be a symbol"); 56 | } 57 | 58 | return; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.SymbolOperations/StringSymbol.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.SymbolOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class StringSymbol : Primitive 36 | { 37 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 38 | { 39 | ScheminString str = (ScheminString) args.Car; 40 | return AtomFactory.GetAtom(str.Value); 41 | } 42 | 43 | public override void CheckArguments(ScheminPair args) 44 | { 45 | IScheminType first = args.Car; 46 | 47 | if (args.Length != 1) 48 | { 49 | throw new BadArgumentsException("expected 1 argument"); 50 | } 51 | 52 | if ((first as ScheminString) == null) 53 | { 54 | throw new BadArgumentsException("argument must be a string"); 55 | } 56 | 57 | return; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.SymbolOperations/SymbolString.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.SymbolOperations 29 | { 30 | using System; 31 | using Environment = Schemin.Evaluate.Environment; 32 | using Schemin.Evaluate; 33 | using Schemin.AST; 34 | 35 | public class SymbolString : Primitive 36 | { 37 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 38 | { 39 | ScheminAtom sym = (ScheminAtom) args.Car; 40 | return new ScheminString(sym.Name); 41 | } 42 | 43 | public override void CheckArguments(ScheminPair args) 44 | { 45 | IScheminType first = args.Car; 46 | 47 | if (args.Length != 1) 48 | { 49 | throw new BadArgumentsException("expected 1 argument"); 50 | } 51 | 52 | if ((first as ScheminAtom) == null) 53 | { 54 | throw new BadArgumentsException("argument must be a symbol"); 55 | } 56 | 57 | return; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.VectorOperations/ListVector.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.VectorOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class ListVector : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminPair list = (ScheminPair) args.Car; 38 | return list.ToVector(); 39 | } 40 | 41 | public override void CheckArguments(ScheminPair args) 42 | { 43 | IScheminType first = args.Car; 44 | 45 | if (args.Length != 1) 46 | { 47 | throw new BadArgumentsException("expected 1 argument"); 48 | } 49 | 50 | if ((first as ScheminPair) == null) 51 | { 52 | throw new BadArgumentsException("first argument must be a list"); 53 | } 54 | 55 | return; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.VectorOperations/Vector.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.VectorOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class Vector : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminVector vec = new ScheminVector(); 38 | 39 | if ((args as ScheminPair) != null) 40 | { 41 | ScheminPair temp = (ScheminPair) args; 42 | foreach (IScheminType type in temp) 43 | { 44 | vec.List.Add(type); 45 | } 46 | } 47 | else 48 | { 49 | vec.List.Add(args); 50 | } 51 | 52 | return vec; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.VectorOperations/VectorFill.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.VectorOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class VectorFill : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminVector vec = (ScheminVector) args.Car; 38 | IScheminType fill = args.ListCdr().Car; 39 | 40 | for (int i = 0; i < vec.List.Count; i++) 41 | { 42 | vec.List[i] = fill; 43 | } 44 | 45 | return new ScheminPair(); 46 | } 47 | 48 | public override void CheckArguments(ScheminPair args) 49 | { 50 | IScheminType first = args.Car; 51 | 52 | if (args.Length != 2) 53 | { 54 | throw new BadArgumentsException("expected 2 arguments"); 55 | } 56 | 57 | if ((first as ScheminVector) == null) 58 | { 59 | throw new BadArgumentsException("first argument must be a vector"); 60 | } 61 | 62 | return; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.VectorOperations/VectorLength.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.VectorOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class VectorLength : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminVector vec = (ScheminVector) args.Car; 38 | return new ScheminInteger(vec.List.Count); 39 | } 40 | 41 | public override void CheckArguments(ScheminPair args) 42 | { 43 | IScheminType first = args.Car; 44 | 45 | if (args.Length != 1) 46 | { 47 | throw new BadArgumentsException("expected 1 argument"); 48 | } 49 | 50 | if ((first as ScheminVector) == null) 51 | { 52 | throw new BadArgumentsException("first argument must be a vector"); 53 | } 54 | 55 | return; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.VectorOperations/VectorList.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.VectorOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class VectorList : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminVector vec = (ScheminVector) args.Car; 38 | return vec.ToList(); 39 | } 40 | 41 | public override void CheckArguments(ScheminPair args) 42 | { 43 | IScheminType first = args.Car; 44 | 45 | if (args.Length != 1) 46 | { 47 | throw new BadArgumentsException("expected 1 argument"); 48 | } 49 | 50 | if ((first as ScheminVector) == null) 51 | { 52 | throw new BadArgumentsException("first argument must be a vector"); 53 | } 54 | 55 | return; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Primitives/Schemin.Primitives.VectorOperations/VectorRef.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Primitives.VectorOperations 29 | { 30 | using Schemin.Evaluate; 31 | using Schemin.AST; 32 | 33 | public class VectorRef : Primitive 34 | { 35 | public override IScheminType Execute(Environment env, Evaluator eval, ScheminPair args) 36 | { 37 | ScheminVector vec = (ScheminVector) args.Car; 38 | ScheminInteger pos = (ScheminInteger) args.ListCdr().Car; 39 | 40 | int pos_int = (int) pos.IntegerValue(); 41 | return vec.List[pos_int]; 42 | } 43 | 44 | public override void CheckArguments(ScheminPair args) 45 | { 46 | IScheminType first = args.Car; 47 | IScheminType second = args.ListCdr().Car; 48 | 49 | if (args.Length != 2) 50 | { 51 | throw new BadArgumentsException("expected 2 arguments"); 52 | } 53 | 54 | if ((first as ScheminVector) == null) 55 | { 56 | throw new BadArgumentsException("first argument must be a vector"); 57 | } 58 | 59 | if ((second as ScheminInteger) == null) 60 | { 61 | throw new BadArgumentsException("second argument must be an integer"); 62 | } 63 | 64 | return; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Tokenize/Token.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Tokenize 29 | { 30 | using System; 31 | 32 | public class Token 33 | { 34 | public TokenType Type; 35 | public string Value; 36 | public int LineNumber; 37 | public int ColNumber; 38 | 39 | public Token(TokenType type, string value) 40 | { 41 | this.Type = type; 42 | this.Value = value; 43 | } 44 | 45 | public override string ToString() 46 | { 47 | return Value; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Schemin/Schemin.Tokenize/TokenType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace Schemin.Tokenize 29 | { 30 | public enum TokenType 31 | { 32 | Symbol, 33 | IntegerLiteral, 34 | DecimalLiteral, 35 | StringLiteral, 36 | BoolLiteral, 37 | CharLiteral, 38 | VectorLiteral, 39 | Quote, 40 | BackQuote, 41 | Comma, 42 | AtComma, 43 | Dot, 44 | OpenParen, 45 | CloseParen 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/ScheminTests/Assembly/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | using System; 29 | using System.Diagnostics; 30 | using System.Reflection; 31 | using System.Resources; 32 | using System.Security; 33 | using System.Security.Permissions; 34 | using System.Runtime.CompilerServices; 35 | using System.Runtime.InteropServices; 36 | 37 | [assembly: AssemblyTitle ("ScheminTests.dll")] 38 | [assembly: AssemblyVersion("0.0.1")] 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/ScheminTests/ScheminTests.PrimitiveTests/StringOperationTests.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Alex Fort 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. The name of the author may not be used to endorse or promote products 14 | * derived from this software without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | namespace ScheminTests.PrimitiveTests 29 | { 30 | using System; 31 | using NUnit.Framework; 32 | using Schemin.Primitives; 33 | using Schemin.AST; 34 | 35 | [TestFixture] 36 | public class StringOperationTests 37 | { 38 | [Test] 39 | public void TestStringLength() 40 | { 41 | var prim = PrimitiveFactory.Get("string-length"); 42 | ScheminString test = new ScheminString("test"); 43 | ScheminInteger result = (ScheminInteger) prim.Execute(null, null, new ScheminPair(test)); 44 | ScheminInteger expected = new ScheminInteger(4); 45 | 46 | Assert.AreEqual(result.IntegerValue(), expected.IntegerValue()); 47 | } 48 | 49 | [Test] 50 | public void TestStringRef() 51 | { 52 | var prim = PrimitiveFactory.Get("string-ref"); 53 | ScheminString test = new ScheminString("test"); 54 | 55 | ScheminPair args = new ScheminPair(test); 56 | args = args.Append(new ScheminInteger(0)); 57 | 58 | ScheminChar result = (ScheminChar) prim.Execute(null, null, args); 59 | char expected = 't'; 60 | 61 | Assert.AreEqual(result.Value, expected); 62 | } 63 | } 64 | } 65 | --------------------------------------------------------------------------------