"Loop" in Prelude #119

Closed
opened 2025-06-12 19:48:54 +00:00 by kavi · 2 comments
Member

The error

=== === === Run 4
Ludus panicked! no match: loop
  on line 83 in prelude:
  >>> 		then loop (y, zs) with {
.............^

The code:

let char_symbols_list = [["a", :a],["b", :b],["c", :c],["d", :d],["e", :e],["f", :f],["g", :g],["h", :h],["i", :i],["j", :j],["k", :k],["l", :l],["m", :m],["n", :n],["o", :o],["p", :p],["q", :q],["r", :r],["s", :s],["t", :t],["u", :u],["v", :w],["w", :w],["x", :x],["y", :y],["z", :z]]

fn get_key_in_list {
  (a_key, []) -> :nil
  (a_key, a_dict) -> {
    let matches = filter(fn (x) -> eq?(a_key, first(x), a_dict), a_dict)
    if any?(matches) then first(matches) else :nil
  }
}

fn char_symbol(a_char) -> get_key_in_list(a_char, char_symbols_list)
print!(char_symbol("d"))
The error ``` === === === Run 4 Ludus panicked! no match: loop on line 83 in prelude: >>> then loop (y, zs) with { .............^ ``` The code: ``` let char_symbols_list = [["a", :a],["b", :b],["c", :c],["d", :d],["e", :e],["f", :f],["g", :g],["h", :h],["i", :i],["j", :j],["k", :k],["l", :l],["m", :m],["n", :n],["o", :o],["p", :p],["q", :q],["r", :r],["s", :s],["t", :t],["u", :u],["v", :w],["w", :w],["x", :x],["y", :y],["z", :z]] fn get_key_in_list { (a_key, []) -> :nil (a_key, a_dict) -> { let matches = filter(fn (x) -> eq?(a_key, first(x), a_dict), a_dict) if any?(matches) then first(matches) else :nil } } fn char_symbol(a_char) -> get_key_in_list(a_char, char_symbols_list) print!(char_symbol("d")) ```
Owner

The arity of the function to eq? in the lambda you pass to filter is weird. I haven't figured out why it's causing a panic, but you can get this to work correctly if that line reads:

let matches = filter (fn (x) -> eq? (a_key, first(x)), a_dict)

I'll try to figure out how to improve this error, or what even is causing it, but that should get your code to work.

The arity of the function to `eq?` in the lambda you pass to filter is weird. I haven't figured out why it's causing a panic, but you can get this to work correctly if that line reads: `let matches = filter (fn (x) -> eq? (a_key, first(x)), a_dict)` I'll try to figure out how to improve this error, or what even is causing it, but that should get your code to work.
Owner

Problem was with higher-arity eq? applications. Fixed in 5c96cd8538, along with the wrong algorithm for neq?

Problem was with higher-arity `eq?` applications. Fixed in https://alea.ludus.dev/twc/ludus/commit/5c96cd853844aad38002e4bbf0099f8eedfd9126, along with the wrong algorithm for `neq?`
scott closed this issue 2025-06-12 20:53:32 +00:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: twc/ludus#119
No description provided.