Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

This closes issue #42, #42
  • Loading branch information...
commit b89cbbb42faf619272707130cda0ab02c50de828 1 parent cf2edc4
Jacob Rothstein authored
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
2  lib/browser.js
@@ -340,7 +340,7 @@
var fnNameTr = translate(fnName),
start = (function() {
- if (/\./(fnNameTr)) {
+ if (fnNameTr.match(/\./)) {
return "";
} else {
return "var ";
View
2  lib/sibilant.js
@@ -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
2  src/core.sibilant
@@ -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

@katspaugh

You could use test().

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

@jbr
Owner

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

```(defmacro match? (regexp string)
  (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.
@katspaugh

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.
Something went wrong with that request. Please try again.