Permalink
Browse files

[ Apparently browsers stopped supporting /regex/(something) ]

This closes issue #42, #42
  • Loading branch information...
1 parent cf2edc4 commit b89cbbb42faf619272707130cda0ab02c50de828 Jacob Rothstein committed Dec 20, 2011
Showing with 3 additions and 3 deletions.
  1. +1 −1 lib/browser.js
  2. +1 −1 lib/sibilant.js
  3. +1 −1 src/core.sibilant
View
@@ -340,7 +340,7 @@
var fnNameTr = translate(fnName),
start = (function() {
- if (/\./(fnNameTr)) {
+ if (fnNameTr.match(/\./)) {
return "";
} else {
return "var ";
View
@@ -393,7 +393,7 @@ macros.defun = (function(fnName, argsAndBody) {
var fnNameTr = translate(fnName),
start = (function() {
- if (/\./(fnNameTr)) {
+ if (fnNameTr.match(/\./)) {
return "";
} else {
return "var ";
View
@@ -156,7 +156,7 @@
(defun macros.defun (fn-name &rest args-and-body)
(defvar fn-name-tr (translate fn-name)
- start (if (/\./ fn-name-tr) "" "var "))
+ start (if (match? /\./ fn-name-tr) "" "var "))
(concat start fn-name-tr " = "
(apply macros.lambda args-and-body)
";\n"))

3 comments on commit b89cbbb

You could use test().

if (/\./.test(fnNameTr)) { /* ... */ }

Owner

jbr replied Feb 2, 2012

The (match? regex string) regex used in this patch expands to string.match(regex). Check out these lines in macros.sibilant:

  (macros.send string 'match regexp))

Is there an advantage to using /regex/.test('string') over 'string'.match(/regex/) as was done in this patch? I've been away from a
computer for a while now, but I seem to remember them being equivalent since we don't need the captures or matches.

test is a simple predicate, it returns true of false.

match returns the array of the matched substring followed by captured group substrings (if any) or null. In case of regexes with the global flag, it returns the array of all matched substrings or null (no captured groups).

A benchmark.

Please sign in to comment.