Skip to content

Commit

Permalink
clean up hash doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwparas committed Dec 22, 2023
1 parent 8315012 commit 9dbfa44
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 21 deletions.
37 changes: 21 additions & 16 deletions crates/steel-core/src/primitives/hashmaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ declare_const_ref_functions!(
pub(crate) fn hashmap_module() -> BuiltInModule {
let mut module = BuiltInModule::new("steel/hash".to_string());
module
.register_value_with_doc("hash", HM_CONSTRUCT, HASH_DOC)
.register_native_fn_definition(HM_CONSTRUCT_DEFINITION)
.register_value("%keyword-hash", SteelVal::FuncV(hm_construct_keywords))
.register_native_fn_definition(HASH_INSERT_DEFINITION)
.register_native_fn_definition(HASH_REF_DEFINITION)
Expand All @@ -47,21 +47,26 @@ pub(crate) fn hashmap_module() -> BuiltInModule {
module
}

const HASH_DOC: DocTemplate<'static> = DocTemplate {
signature: "(hash key val ...) -> hash?",
params: &["key : hashable?", "val : any/c"],
description: r#"Creates an immutable hash table with each given `key` mapped to the following `val`; each key must have a val, so the total number of arguments must be even.
Note, the key must be hashable."#,
examples: &[(
"> (hash 'a 10 'b 20)",
r#"=> #<hashmap {
'a: 10,
'b: 20,
}>"#,
)],
};

/// Creates an immutable hash table with each given `key` mapped to the following `val`.
/// Each key must have a val, so the total number of arguments must be even.
///
///
/// (hash key val ...) -> hash?
///
/// key : hashable?
/// val : any/c
///
/// Note: the keys must be hashable.
///
/// # Examples
/// ```scheme
/// > (hash 'a 10 'b 20)",
/// r#"=> #<hashmap {
/// 'a: 10,
/// 'b: 20,
/// }>"#,
/// ```
#[steel_derive::native(name = "hash", arity = "AtLeast(0)")]
pub fn hm_construct(args: &[SteelVal]) -> Result<SteelVal> {
let mut hm = HashMap::new();

Expand Down
4 changes: 4 additions & 0 deletions docs/src/builtins/#%private_steel_mhash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# #%private/steel/mhash
### **mhash**
### **mhash-ref**
### **mhash-set!**
10 changes: 10 additions & 0 deletions docs/src/builtins/#%private_steel_mvector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# #%private/steel/mvector
### **make-mutable-vector**
### **mutable-vector->list**
### **mutable-vector-empty?**
### **mutable-vector-from-list**
### **mutable-vector-len**
### **mutable-vector-pop!**
### **mutable-vector-push!**
### **mutable-vector-ref**
### **mutable-vector-set!**
5 changes: 5 additions & 0 deletions docs/src/builtins/#%private_steel_reader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# #%private/steel/reader
### **new-reader**
### **reader-empty?**
### **reader-push-string**
### **reader-read-one**
20 changes: 20 additions & 0 deletions docs/src/builtins/steel_base.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ Returns the first element of the list l.
> (first '(1 2)) ;; => 1
> (first (cons 2 3)) ;; => 2
```
### **hash**
Creates an immutable hash table with each given `key` mapped to the following `val`.
Each key must have a val, so the total number of arguments must be even.


(hash key val ...) -> hash?

key : hashable?
val : any/c

Note: the keys must be hashable.

#### Examples
```scheme
> (hash 'a 10 'b 20)",
r#"=> #<hashmap {
'a: 10,
'b: 20,
}>"#,
```
### **hash-contains?**
Checks whether the given map contains the given key. Key must be hashable.

Expand Down
1 change: 0 additions & 1 deletion docs/src/builtins/steel_core/filesystem.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/src/builtins/steel_core/result.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/src/builtins/steel_core/types.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/src/builtins/steel_hash.hd

This file was deleted.

20 changes: 20 additions & 0 deletions docs/src/builtins/steel_hash.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
# steel/hash
### **hash**
Creates an immutable hash table with each given `key` mapped to the following `val`.
Each key must have a val, so the total number of arguments must be even.


(hash key val ...) -> hash?

key : hashable?
val : any/c

Note: the keys must be hashable.

#### Examples
```scheme
> (hash 'a 10 'b 20)",
r#"=> #<hashmap {
'a: 10,
'b: 20,
}>"#,
```
### **hash-contains?**
Checks whether the given map contains the given key. Key must be hashable.

Expand Down
1 change: 0 additions & 1 deletion docs/src/builtins/steel_pords.md

This file was deleted.

0 comments on commit 9dbfa44

Please sign in to comment.