Skip to content

Commit

Permalink
some flailing towards starting a physics section
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfitz committed Oct 25, 2019
1 parent 8ffd3fd commit 1f30068
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 12 deletions.
25 changes: 25 additions & 0 deletions msg/COS_Dot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env node

const cos = require('./cosmic');

cos.intro(".");

cos.add(`define dotify:1 | ? pre | ? act | ? rem |
if (= 0 | list-length $rem) (append $act $pre) |
assign next (head $rem) |
if (not | = . $next) (dotify:1 (append $act $pre) $next (tail $rem)) |
dotify:1 $pre (vector $act | head | tail $rem) (tail | tail $rem)`);

cos.add(`define dotify | ? lst |
dotify:1 (vector) (head $lst) (tail $lst)`);

cos.add(`list= (dotify | vector 1 2 . 3 4) (vector 1 (vector 2 3) 4)`);
cos.add(`list= (dotify | vector 1 2 . 3 . 4 5) (vector 1 (vector (vector 2 3) 4) 5)`);

cos.add(`define translate | assign prev $translate | ? x |
if (not | function? $x) (prev $x) |
if (<= (list-length $x) 1) (prev $x) |
prev | dotify $x`);

cos.add(`= + . 5 . 5 10`);
cos.add(`= + . (- + . 4 . 4 3) . 5 * . 5 . 2`);
13 changes: 13 additions & 0 deletions msg/COS_Element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env node

const cos = require('./cosmic');

cos.intro("proton:electron:mass:ratio");
cos.intro("proton:mass");
cos.intro("neutron:mass");
cos.intro("electron:mass");

cos.add("define float:= | ? x | ? y | within (frac (+ $x $y) 200000) $x $y");
cos.add("float:= $proton:mass | * $electron:mass | decimal 1836 | vector 1 5 2 6 7 3");
cos.add("float:= $electron:mass | * $proton:mass | decimal 0 | vector 0 0 0 5 4 4 6 1 7");
cos.add("float:= $neutron:mass | * $proton:mass | decimal 1 | vector 0 0 1 3 7 8 4 2");
2 changes: 2 additions & 0 deletions msg/COS_Element.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# PHYSICS introduce the elements

7 changes: 7 additions & 0 deletions msg/COS_List.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,10 @@ cos.add(`define list:reverse | ? x:list |

cos.add(`list= (list:reverse | vector 1 2 3) (vector 3 2 1)`);
cos.add(`list= (list:reverse | vector 50 1 33 99) (vector 99 33 1 50)`);

cos.intro("append");
cos.add(`define append | ? x | ? lst |
if (= 0 | list-length $lst) (vector $x) |
prepend (head | $lst) | append $x | tail $lst`);

cos.add(`list= (vector 1 2 5) | append 5 | vector 1 2`);
7 changes: 0 additions & 7 deletions msg/COS_NewType.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ cos.add(`define list-append | lambda (lst1 lst2) |

cos.add(`list= (vector 1 2 3 4 5 6) | list-append (vector 1 2 3) (vector 4 5 6)`);

cos.intro("append");
cos.add(`define append | lambda (x lst) |
if (= 0 | list-length $lst) (vector $x) |
prepend (head | $lst) | append $x | tail $lst`);

cos.add(`list= (vector 1 2 5) | append 5 | vector 1 2`);

cos.add(`define select-match | lambda (test lst) |
if (= 0 | list-length $lst) $lst |
if (not | test | head $lst) (select-match $test | tail $lst) |
Expand Down
47 changes: 47 additions & 0 deletions msg/DEPEND.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

# set(req_COS_Intro COS_License)
set(req_COS_AndLogic COS_TrueFalse)
set(req_COS_OrLogic COS_TrueFalse)
set(req_COS_ListPre COS_Cons COS_TrueFalse)
set(req_COS_Map COS_ListPre)
set(req_COS_Series COS_Map COS_OrLogic COS_If)
set(req_COS_Translate COS_ListPre)
set(req_COS_List COS_ListPre COS_Translate COS_OrLogic)
set(req_COS_Dot COS_List)
set(req_COS_Element COS_List COS_Series)
set(req_COS_Let COS_List)
set(req_COS_MultipleParameter COS_Let)
set(req_COS_Implication COS_TrueFalse)
set(req_COS_Set COS_List COS_Implication)
set(req_COS_Graph COS_MultipleParameter)
set(req_COS_Begin COS_Let COS_Mutable)
set(req_COS_Hash COS_MultipleParameter)
set(req_COS_MutableStructure COS_List COS_Let COS_Map)
set(req_COS_Turing COS_MultipleParameter COS_Hash)
set(req_COS_Quote COS_List COS_Map)
set(req_COS_NewType COS_MultipleParameter COS_Set COS_Quote COS_Begin)
set(req_COS_Unless COS_TrueFalse COS_Hash COS_Begin COS_Map COS_Series)
set(req_COS_NOT COS_Unless)
set(req_COS_AND COS_Unless)
set(req_COS_OR COS_Unless)
set(req_COS_NOR COS_Unless)
set(req_COS_OSC COS_Unless)
set(req_COS_SR COS_Unless)
set(req_COS_D COS_Unless)
set(req_COS_UnlessProbe COS_NOT COS_AND)
set(req_COS_Message COS_Intro COS_List COS_Quote)
set(req_COS_JavaPrep COS_NewType COS_Series COS_Hash)
set(req_COS_JavaTest COS_JavaPrep)
set(req_COS_JavaValidate COS_JavaTest)
set(req_COS_Geo COS_NewType COS_Hash)
set(req_COS_JList_impl COS_JavaPrep)
set(req_COS_JList_test COS_JList_impl)
set(req_COS_JListIterator_impl COS_JList_impl)
set(req_COS_JDoor COS_JavaPrep)
set(req_COS_JThing COS_JavaPrep)
set(req_COS_JRoom COS_JavaPrep)
set(req_COS_JNamed COS_JavaPrep)
set(req_COS_JWorld COS_JavaPrep)
set(req_COS_JRobo COS_JavaPrep)
set(req_COS_JRoom_test COS_JRoom COS_JWorld COS_JDoor COS_JRobo COS_JThing COS_JNamed
COS_JList_impl COS_JListIterator_impl)
23 changes: 23 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,29 @@ FILE(WRITE ${WORK}/setup.cmake "
set(TSNODE \"${CMAKE_SOURCE_DIR}/node_modules/.bin/ts-node\")
")

include(${CMAKE_SOURCE_DIR}/msg/DEPEND.cmake)
set_property(GLOBAL PROPERTY msg_list)

function(expand)
get_property(tmp GLOBAL PROPERTY msg_list)
foreach(depend ${ARGV})
get_property(have_${depend} GLOBAL PROPERTY have_${depend})
if (NOT have_${depend})
set(req ${req_${depend}})
if (req)
expand(${req})
endif()
get_property(tmp GLOBAL PROPERTY msg_list)
set_property(GLOBAL PROPERTY msg_list ${tmp} ${depend})
set(have_${depend} 1)
set_property(GLOBAL PROPERTY have_${depend} 1)
endif()
endforeach()
endfunction()

expand(${COSMIC_DEPENDS})
get_property(COSMIC_DEPENDS GLOBAL PROPERTY msg_list)

set(ACTIVE_DEPENDS)
set(ACTIVE_DEPENDS_SHORT "")
set(EXTRA_DEPEND_pl ${MSG}/cosmic.pm)
Expand Down
1 change: 1 addition & 0 deletions src/cosmicos/Cons.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Cons {
if (Std.is(e,BigInteger)) return e;
if (Std.is(e,String)) return e;
if (Std.is(e,BitString)) return e;
if (Std.is(e,Float)) return e;
var c = new Cursor(e);
var lst = new Array<Dynamic>();
var len = c.length();
Expand Down
13 changes: 10 additions & 3 deletions src/cosmicos/Evaluate.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Evaluate {
return str;
}
if (Std.is(e0,Int)||Std.is(e0,BigInteger)||Std.is(e0,BitString)||
Std.is(e0,String)) {
Std.is(e0,String)||Std.is(e0,Float)) {
return e0;
}
var cursor = new Cursor(e0);
Expand Down Expand Up @@ -292,6 +292,7 @@ class Evaluate {
vocab.set("unary", 255); //0b11111111

mem.add(vocab.get("intro"), function(x){ return 1; });
mem.add(vocab.get("assume"), function(x){ return x; });
addStdMin();
evaluateLine("@ 1 1");
evaluateLine("@ true 1");
Expand All @@ -314,7 +315,7 @@ class Evaluate {
mem.add(vocab.get("function?"), function(x){ return !(Std.is(x,Int)||Std.is(x,Float)||Std.is(x,BigInteger)||Std.is(x,String)||Std.is(x,BitString)||Std.is(x,Bool)); });
mem.add(vocab.get("type?"), function(x) { return "type " + Std.is(x,Int) + " " + Std.is(x,Float) + " " + Std.is(x,Bool); });
mem.add(vocab.get("translate"), function(x){
if (Std.is(x,Int)||Std.is(x,BigInteger)||Std.is(x,String)||Std.is(x,BitString)) return x;
if (Std.is(x,Int)||Std.is(x,BigInteger)||Std.is(x,String)||Std.is(x,BitString)||Std.is(x,Float)) return x;
var rep = function(x) {
}
var len = Cons.car(x);
Expand Down Expand Up @@ -397,7 +398,13 @@ class Evaluate {
evaluateLine("@ is:square | ? x | has-square-divisor-within $x $x");
evaluateLine("@ undefined 999"); // this should be a special value, not 999 :-)
evaluateLine("@ even | ? x | = 0 | - $x | * 2 | div $x 2");

// evaluateLine("@ proton:electron:mass:ratio 1836.15267343f");
mem.add(vocab.get("proton:electron:mass:ratio"), 1836.15267343);
mem.add(vocab.get("proton:mass"), 1.6726192369e-27); // number should never be revealed
// since arbitrary units (kg)
mem.add(vocab.get("neutron:mass"), 1.674927471e-27); // ditto
mem.add(vocab.get("electron:mass"), 9.10938356e-31); // ditto

// meta-lambda-function
id_lambda0 = vocab.get("??");
}
Expand Down
10 changes: 8 additions & 2 deletions src/cosmicos/Parse.hx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class Parse {
var str : String = cast v;
var ch0 = str.charAt(0);
if (ch0<'0'||ch0>'9') {
if (ch0 == ":" || ch0 == ".") {
if ((ch0 == ":" || ch0 == ".") && str.length > 1) { // should use a different encoding
v = new BitString(str);
} else if (ch0 == "U" && ~/^U1*U$/.match(str)) {
// unary number e.g. U111U represent as string
Expand All @@ -282,7 +282,13 @@ class Parse {
}
}
} else {
v = Std.parseInt(str);
if (str.charAt(str.length - 1) == 'f') {
// Secret way to insert floats for physical constants.
// Please don't use in message.
v = Std.parseFloat(str.substr(0, str.length - 1));
} else {
v = Std.parseInt(str);
}
}
e[i] = v;
}
Expand Down

0 comments on commit 1f30068

Please sign in to comment.