Skip to content
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

Braindump #1

Open
josephzidell opened this issue Aug 27, 2022 · 3 comments
Open

Braindump #1

josephzidell opened this issue Aug 27, 2022 · 3 comments

Comments

@josephzidell
Copy link
Owner

josephzidell commented Aug 27, 2022

  • Comments // ... and /* ... */
  • keywords and tokens are case sensitive
  • should tokens use UTF-8?
  • std practice: lets, consts, and methods are camelCase; classes are PascalCase
  • variable regex: [_a-zA-Z][_a-zA-Z0-9]*\??
  • if var ends with ? must be boolean
  • methodName regex: [_a-zA-Z][_a-zA-Z0-9]*\??!?
  • if methodName ends with ? must return boolean
  • if methodName ends with ! it can throw an error (? comes before !)
  • semicolons not needed
  • grouping expressions ( ... )
  • code block { ... }
  • decide how equality checks will happen (==, !=, ===, !==, ~=, ~==)
  • cannot have assignment in if condition
  • ifs, fors, switches don't need parens for args, must have braces, except for if after statement
  • if can be used in 2 ways: if condition { foo } or foo if condition (in latter case, braces aren't allowed)
  • if/then/else/elseif
  • c ? b1 : b2 or c ?: b2
  • for i = 0, i < 10, i++ { ... }
  • for
  • multiple return
  • try/catch
  • not !
  • comparison a <=> b (numbers are simple, strings are by char, tuples/arrays are not allowed) return -1, 0, or 1
  • method call foo()
  • args order: required, with default, variardic (must be array)
  • closure (a, b) -> ...
  • generics
  • hierarchy .
  • && ||
  • switch cases break auto, use nextcase to fall through, multiple cases together
  • enum
  • :symbols see https://elixir-lang.org/getting-started/basic-types.html#atoms
  • figure out strings over multiple lines
  • how to combine arrays [...] + [...] returns new array. Same for tuple <...> + <...>
  • concat strings 'a' + 'b' returns new string
  • import
  • regex
  • hex 0xabc / oct 0o777
  • classes, abstract, extends (can extend multiple and implement multiple - FCFS in case of same method names)
@josephzidell
Copy link
Owner Author

josephzidell commented Aug 27, 2022

  • figure out do/while

Ranges

  • Ex: 1..4 for i in 1..4 { ... }, const myArray = 33..4000
  • generates an array
  • always inclusive
  • can go 10..1
  • only integers
  • no spaces

For

  • for i: v in array { ... }
  • for i: v in tuple { ... }
  • for k: v in POJO { ... }

Control flow

  • return from a method
  • skip in a for or while loop

Errors

  • try/catch/throw
  • can throw an object or string (string is wrapped in Error class`
  • catch must specify type

Classes

  • new MyClass()
  • name must start with uppercase letter
  • this
  • parent class super(), can do super().super()...

Strings

  • printf / sprintf
  • print
  • 'foo'.length
  • 'a' + 'b' returns new string
  • ascii to char chr()
  • char to ascii ord()
  • 'd'.times(5)
  • uppercase/lowercase
  • substr (0-based) 'foo'[2], 'foo'[1:2], 'foo'[1:], 'foo'[:2], figure out negative numbers, always inclusive, same for tuples

@josephzidell
Copy link
Owner Author

Numbers

  • pre- or post- increment and decrement ++/--
  • arithmetic + - * / % ^
  • parens for priority
  • can be negative
  • can have exponent 1e4, 24e-3

@josephzidell
Copy link
Owner Author

Data Structures

  • array hold items of the same type myArray = [1, 2, 3, 4]. Can be sorted
  • tuples hold items of varying types myTuple = <1, 'fun', 3.4, false, nil>. Cannot be sorted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant