Skip to content

Commit 7b4b074

Browse files
committed
Print documentation of the module if it is passed to the help! function
1 parent 226ce16 commit 7b4b074

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

lib/src/metta/runner/stdlib/stdlib.metta

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -875,14 +875,14 @@
875875
(@doc-formal (@item $atom) (@kind atom) (@type $type) (@desc "No documentation")) ))))
876876

877877
(@doc help!
878-
(@desc "Function prints documentation for the input atom. Without parameters prints the list of the stdlib functions.")
878+
(@desc "Function prints documentation for the input atom or module. Without parameters prints the list of the corelib functions.")
879879
(@params (
880-
(@param "Input to get documentation for")))
880+
(@param "Input to get documentation for atom or module")))
881881
(@return "Unit atom"))
882882
(: help! (-> Atom (->)))
883883
(= (help! $atom)
884-
(let $corelib-space (module-space-no-deps (mod-space! corelib))
885-
(case (get-doc $corelib-space $atom) (
884+
(let $top-space (mod-space! top)
885+
(case (get-doc $top-space $atom) (
886886
((@doc-formal (@item $item) (@kind function) (@type $type) (@desc $descr)
887887
(@params $params)
888888
(@return (@type $ret-type) (@desc $ret-desc)))
@@ -899,17 +899,28 @@
899899
() ))
900900
($other (Error $other "Cannot match @doc-formal structure") )))))
901901

902+
(: help! (-> Symbol (->)))
903+
(= (help! $mod)
904+
(let $space (module-space-no-deps (mod-space! $mod))
905+
(help-space! $space) ))
906+
902907
(: help! (-> (->)))
903-
(= (help!)
904-
(let $corelib-space (module-space-no-deps (mod-space! corelib))
905-
(unify $corelib-space (@doc $name (@desc $desc) $params $ret)
908+
(= (help!) (help! corelib))
909+
910+
(@doc help-space!
911+
(@desc "Function prints documentation for all of the atoms from the given space.")
912+
(@params (
913+
(@param "Space to print documentation for")))
914+
(@return "Unit atom"))
915+
(: help-space! (-> SpaceType (->)))
916+
(= (help-space! $space)
917+
(unify $space (@doc $name (@desc $desc) $params $ret)
906918
(let () (println! (format-args "{}\n\t{}" ($name $desc))) Empty)
907-
Empty)))
908-
(= (help!)
909-
(let $corelib-space (module-space-no-deps (mod-space! corelib))
910-
(unify $corelib-space (@doc $name (@desc $desc))
919+
Empty))
920+
(= (help-space! $space)
921+
(unify $space (@doc $name (@desc $desc))
911922
(let () (println! (format-args "{}\n\t{}" ($name $desc))) Empty)
912-
Empty)))
923+
Empty))
913924

914925
(@doc help-param!
915926
(@desc "Function used by function help! to output parameters using println!")

0 commit comments

Comments
 (0)