[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help with map match
From: |
Ricardo Wurmus |
Subject: |
Re: Help with map match |
Date: |
Fri, 30 Nov 2018 03:45:17 +0100 |
User-agent: |
mu4e 1.0; emacs 26.1 |
Hi,
> I want the procedure to return #t if a match is found and I want it to
> match if it begins with the same e.g. "rollup-plugin" should match
> "rollup-plugin-node-resolve" and return #t
> Else #f
> This did not work:
> (use-modules (ice-9 match))
>
> (define x
> '("ts" "test"))
> (map (match x
> ("test") #t)
> (else #f) x)
“map” requires a procedure and a list as its arguments, applies the
procedure to every element and then returns a new list with the results.
Since you just want a single boolean as the return value you may want to
use “any” instead, which tells you if a procedure returned #t for “any”
of the items in a list.
--8<---------------cut here---------------start------------->8---
(use-modules (srfi srfi-1))
(define (blacklisted? pkg-name)
(string-prefix? "rollup-" pkg-name))
(any blacklisted?
'("rollup-plugin" "rollup-plugin-foo")) ; => #t
(any blacklisted?
'("all" "is" "good")) ; => #f
--8<---------------cut here---------------end--------------->8---
“blacklisted?” can then implement whatever logic you need.
--
Ricardo