Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling help! without parameters shows list of stdlib functions #817

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/src/metta/runner/stdlib/stdlib.metta
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@
(@doc-formal (@item $atom) (@kind atom) (@type $type) (@desc "No documentation")) )))))

(@doc help!
(@desc "Function prints documentation for the input atom.")
(@desc "Function prints documentation for the input atom. Without parameters prints the list of the stdlib functions.")
(@params (
(@param "Input to get documentation for")))
(@return "Unit atom"))
Expand All @@ -839,6 +839,16 @@
() ))
($other (Error $other "Cannot match @doc-formal structure") ))))

(: help! (-> (->)))
(= (help!) (let $top-space (mod-space! top)
(unify $top-space (@doc $name (@desc $desc) $params $ret)
(let () (println! (format-args "{}\n\t{}" ($name $desc))) Empty)
Empty)))
(= (help!) (let $top-space (mod-space! top)
(unify $top-space (@doc $name (@desc $desc))
(let () (println! (format-args "{}\n\t{}" ($name $desc))) Empty)
Empty)))

(@doc help-param!
(@desc "Function used by function help! to output parameters using println!")
(@params (
Expand Down
7 changes: 7 additions & 0 deletions repl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ fn main() -> Result<()> {
}
}

fn show_welcome_message() {
println!("Visit https://metta-lang.dev/ for tutorials.");
println!("Execute !(help!) to get list of the standard library functions.");
}

// To debug rustyline:
// RUST_LOG=rustyline=debug cargo run --example example 2> debug.log
fn start_interactive_mode(repl_params: ReplParams, mut metta: MettaShim) -> rustyline::Result<()> {
Expand Down Expand Up @@ -137,6 +142,8 @@ fn start_interactive_mode(repl_params: ReplParams, mut metta: MettaShim) -> rust
}
}

show_welcome_message();

//The Interpreter Loop
loop {

Expand Down
Loading