aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/library/lux/abstract/functor.lux3
-rw-r--r--stdlib/source/library/lux/control/function/inline.lux50
-rw-r--r--stdlib/source/test/lux/control/function.lux4
-rw-r--r--stdlib/source/test/lux/control/function/inline.lux32
4 files changed, 85 insertions, 4 deletions
diff --git a/stdlib/source/library/lux/abstract/functor.lux b/stdlib/source/library/lux/abstract/functor.lux
index fb5f412a3..fb3dab4c8 100644
--- a/stdlib/source/library/lux/abstract/functor.lux
+++ b/stdlib/source/library/lux/abstract/functor.lux
@@ -9,9 +9,6 @@
(-> (f a) (f b))))
each)))
-(type: .public (Fix f)
- (f (Fix f)))
-
(type: .public (Or f g)
(All (_ a) (.Or (f a) (g a))))
diff --git a/stdlib/source/library/lux/control/function/inline.lux b/stdlib/source/library/lux/control/function/inline.lux
new file mode 100644
index 000000000..ef0836888
--- /dev/null
+++ b/stdlib/source/library/lux/control/function/inline.lux
@@ -0,0 +1,50 @@
+(.using
+ [library
+ [lux "*"
+ ["[0]" meta]
+ [abstract
+ ["[0]" monad {"+" do}]]
+ [control
+ ["<>" parser
+ ["<[0]>" code {"+" Parser}]]]
+ [data
+ [collection
+ ["[0]" list ("[1]#[0]" monad)]]]
+ ["[0]" macro
+ ["[0]" code]
+ [syntax {"+" syntax:}
+ ["|[0]|" export]]]]])
+
+(def: declaration
+ (Parser [Text (List Code)])
+ (<code>.form (<>.and <code>.local_symbol (<>.some <code>.any))))
+
+(def: inline
+ (Parser [Code [Text (List Code)] Code Code])
+ (|export|.parser
+ ($_ <>.and
+ ..declaration
+ <code>.any
+ <code>.any
+ )))
+
+(syntax: .public (inline: [[privacy [name parameters] type term] ..inline])
+ (do [! meta.monad]
+ [@ meta.current_module_name
+ g!parameters (|> (macro.symbol "parameter")
+ (list.repeated (list.size parameters))
+ (monad.all !))
+ .let [inlined (` (("lux in-module"
+ (~ (code.text @))
+ (.: (~ type)
+ (.function ((~ (code.local_symbol name)) (~+ parameters))
+ (~ term))))
+ (~+ (list#each (function (_ g!parameter)
+ (` ((~' ~) (~ g!parameter))))
+ g!parameters))))
+ g!parameters (|> g!parameters
+ (list#each (function (_ parameter)
+ (list parameter (` (~! <code>.any)))))
+ list#conjoint)]]
+ (in (list (` ((~! syntax:) (~ privacy) ((~ (code.local_symbol name)) [(~+ g!parameters)])
+ (.# (~! meta.monad) (~' in) (.list (.`' (~ inlined))))))))))
diff --git a/stdlib/source/test/lux/control/function.lux b/stdlib/source/test/lux/control/function.lux
index d9444edd1..eed6c9635 100644
--- a/stdlib/source/test/lux/control/function.lux
+++ b/stdlib/source/test/lux/control/function.lux
@@ -17,7 +17,8 @@
["[1][0]" contract]
["[1][0]" memo]
["[1][0]" mixin]
- ["[1][0]" mutual]])
+ ["[1][0]" mutual]
+ ["[1][0]" inline]])
(def: .public test
Test
@@ -62,4 +63,5 @@
/memo.test
/mixin.test
/mutual.test
+ /inline.test
))))
diff --git a/stdlib/source/test/lux/control/function/inline.lux b/stdlib/source/test/lux/control/function/inline.lux
new file mode 100644
index 000000000..7c05e39e0
--- /dev/null
+++ b/stdlib/source/test/lux/control/function/inline.lux
@@ -0,0 +1,32 @@
+(.using
+ [library
+ [lux "*"
+ ["_" test {"+" Test}]
+ [abstract
+ [monad {"+" do}]]
+ [math
+ ["[0]" random]
+ [number
+ ["i" int]]]]]
+ [\\library
+ ["[0]" /]])
+
+(template: (!quadrance/2 m0 m1)
+ [(i.+ (i.* m0 m0) (i.* m1 m1))])
+
+(/.inline: .public (quadrance/2 m0 m1)
+ (-> Int Int Int)
+ (!quadrance/2 m0 m1))
+
+(def: .public test
+ Test
+ (<| (_.covering /._)
+ (do [! random.monad]
+ [.let [measurement (# ! each (i.% +1000) random.int)]
+ m0 measurement
+ m1 measurement])
+ ($_ _.and
+ (_.cover [/.inline:]
+ (i.= (..!quadrance/2 m0 m1)
+ (..quadrance/2 m0 m1)))
+ )))