Courses/CS 460/Fall 2005/Homework/Josh Cain/Oct 15

From CSWiki

< Courses | CS 460 | Fall 2005 | Homework | Josh Cain
Revision as of 17:00, 15 October 2005 by Jcain (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

[edit] Oct 15 Homework, Josh Cain

Drop

local Drop in
    proc {Drop In Num ?Out} H T in
        choice
            In = nil
            Out = nil
        []
            Num = 0
            In = H|T
            Out = H|{Drop T 0}
        []
            (Num > 0) = true
            In = H|T
            Out = {Drop T Num - 1}
        end
    end
    {Browse {SearchAll fun {$} {Drop [1 2 3 4 5 6 8] 3} end}}
end

Filter *Presented in class, and it was a good example

local Filter in
    proc {Filter In Func ?Out} H T in
        choice
            In = nil
            Out = nil
        []
            In = H|T
            {Func H} = true
            Out = H|{Filter T Func}
        []
            In = H|T
            {Func H} = false
            Out = {Filter T Func}
        end
    end
    {Browse {SearchAll fun {$} {Filter[1 2 3 4 5 6 8] IsOdd} end}}
end

Length

local Length in
    proc {Length In ?L}
        choice
            In = nil
            L = 0
        [] T in
            In = _|T
            L = {Length T} + 1
        end
    end
    {Browse {SearchAll fun {$} {Length [1 2 3 4 5 6 8]} end}}
end

Map

local Map in
    proc {Map In Func ?Out} H T in
        choice
            In = nil
            Out = nil
        []
            In = H|T
            Out = {Func H}|{Map T Func}
        end
    end
    {Browse {SearchAll fun {$} {Map [1 2 3 4 5 6 8] IntToFloat} end}}
end