New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port simple Char functions from JavaScript to Elm #130

Merged
merged 2 commits into from Jan 23, 2015

Conversation

Projects
None yet
2 participants
@jonathanhefner
Contributor

jonathanhefner commented Jan 22, 2015

I'm not sure if this is wanted or not, but I figure it doesn't hurt to offer.

I ported the Native.Char functions that do not use the JavaScript standard lib to pure Elm. My reasons for doing so:

  • Inspecting / understanding the implementation is easier.
  • Any tooling (static analysis, optimization, test coverage) that Elm has or will have can now target these.
  • If Elm itself is ever ported to another runtime, these will now be freebies.
Show outdated Hide outdated src/Char.elm
{-| True for ASCII hexadecimal digits `[0-9a-fA-F]`. -}
isHexDigit : Char -> Bool
isHexDigit = Native.Char.isHexDigit
isHexDigit char =
isDigit char || isBetween 'a' 'f' char || isBetween 'A' 'Z' char

This comment has been minimized.

@evancz

evancz Jan 22, 2015

Member

Should the Z be an F?

@evancz

evancz Jan 22, 2015

Member

Should the Z be an F?

This comment has been minimized.

@jonathanhefner

jonathanhefner Jan 22, 2015

Contributor

Absolutely. I ran the tests... on master (FML). Fixing now.

@jonathanhefner

jonathanhefner Jan 22, 2015

Contributor

Absolutely. I ran the tests... on master (FML). Fixing now.

Show outdated Hide outdated src/Char.elm
isBetween : Char -> Char -> Char -> Bool
isBetween low high char =
let code = toCode char
in (code >= toCode low) && (code <= toCode high)

This comment has been minimized.

@jonathanhefner

jonathanhefner Jan 23, 2015

Contributor

The Basics module isn't auto-imported here, so (&&), (>=), and (<=) are undefined.

Is it safe to import Basics (..)? I assume the reason to not do so is to avoid circular dependencies...? If that's the case, is it uncouth to use Native.Basics.and, etc?

@jonathanhefner

jonathanhefner Jan 23, 2015

Contributor

The Basics module isn't auto-imported here, so (&&), (>=), and (<=) are undefined.

Is it safe to import Basics (..)? I assume the reason to not do so is to avoid circular dependencies...? If that's the case, is it uncouth to use Native.Basics.and, etc?

This comment has been minimized.

@evancz

evancz Jan 23, 2015

Member

I'd just import the functions in question: import Basics ((&&), (>=), (<=))

It is fine as long as the tests run. If there's a circular dependency, it'll just endlessly initialize modules until some piece of technology tells you to stop.

@evancz

evancz Jan 23, 2015

Member

I'd just import the functions in question: import Basics ((&&), (>=), (<=))

It is fine as long as the tests run. If there's a circular dependency, it'll just endlessly initialize modules until some piece of technology tells you to stop.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jan 23, 2015

Member

Looks great, thank you!

Member

evancz commented Jan 23, 2015

Looks great, thank you!

@evancz evancz merged commit b0847df into elm:master Jan 23, 2015

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment