Skip to content

Missing type error for PLVector #38

@vektor8891

Description

@vektor8891

Let's say I have a vector of numbers [9,5,6,5], and I want to replace half of them with "xxx".

This is the correct solution:

(defn mask-digit [digits index]
  (if (>= index 2) "xxx"
    (str (get digits index))
    ))
(print (map (mask-digit [9,5,6,5]) [0 1 2 3])) ; > [9,5,xxx,xxx]

If I remove the str, I get an error (which I expected because I want to mix strings and numbers in the same vector):

(defn mask-digit [digits index]
  (if (>= index 2) "xxx"
    (get digits index)
    ))
(print (map (mask-digit [9,5,6,5]) [0 1 2 3])) ; > Type Error! Expected 'Number', but got 'String'

The funny thing is that if I list the vector of indexes in the second argument in reverse order, the error disappears and the script fails silently:

(defn mask-digit [digits index]
  (if (>= index 2) "xxx"
    (get digits index)
    ))
(print (map (mask-digit [9,5,6,5]) [3 2 1 0])) ; > [No output]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions