Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

JavaScript alternative

Name: Anonymous 2008-12-24 12:26

Is there any language similar to javascript but which can compile to binary?

Name: Anonymous 2008-12-24 12:46

How similar?

Name: Anonymous 2008-12-24 12:47

Scheme

Name: Anonymous 2008-12-24 13:10

>>2
Prototypes,type inference/no type declarations,C-like syntax,flexible functions with ability to return (functions)}.

Name: Anonymous 2008-12-24 13:18

(copied from wiki)
JavaScript supports all the structured programming syntax in C (e.g., if statements, while loops, switch statements, etc.). One partial exception is scoping: C-style block-level scoping is not supported. JavaScript 1.7, however, supports block-level scoping with the let keyword. Like C, JavaScript makes a distinction between expressions and statements.

[edit] Dynamic

dynamic typing
    As in most scripting languages, types are associated with values, not variables. For example, a variable x could be bound to a number, then later rebound to a string. JavaScript supports various ways to test the type of an object, including duck typing.[10]
objects as associative arrays
    JavaScript is almost entirely object-based. Objects are associative arrays, augmented with prototypes (see below). Object property names are associative array keys: obj.x = 10 and obj["x"] = 10 are equivalent, the dot notation being merely syntactic sugar. Properties and their values can be added, changed, or deleted at run-time. The properties of an object can also be enumerated via a for...in loop
Also String[index] as array elements

run-time evaluation(NOT REQUIRED)
    JavaScript includes an eval function that can execute statements provided as strings at run-time.

[edit] Functional

first-class functions
    Functions are first-class; they are objects themselves. As such, they have properties and can be passed around and interacted with like any other object.
inner functions and closures
    Inner functions (functions defined within other functions) are created each time the outer function is invoked, and variables of the outer functions for that invocation continue to exist as long as the inner functions still exist, even after that invocation is finished (e.g. if the inner function was returned, it still has access to the outer function's variables) — this is the mechanism behind closures within JavaScript.

[edit] Prototype-based

prototypes
    JavaScript uses prototypes instead of classes for defining object properties, including methods, and inheritance. It is possible to simulate many class-based features with prototypes in JavaScript.
functions as object constructors
    Functions double as object constructors along with their typical role. Prefixing a function call with new creates a new object and calls that function with its local this keyword bound to that object for that invocation. The function's prototype property determines the new object's prototype.
functions as methods
    Unlike many object-oriented languages, there is no distinction between a function definition and a method definition. Rather, the distinction occurs during function calling; a function can be called as a method. When a function is invoked as a method of an object, the function's local this keyword is bound to that object for that invocation.

[edit] Miscellaneous

run-time environment(A COMPILER IS REQUIRED)
    JavaScript typically relies on a run-time environment (e.g. in a web browser) to provide objects and methods by which scripts can interact with "the outside world". (This is not a language feature per se, but it is common in most JavaScript implementations.)
variadic functions
    An indefinite number of parameters can be passed to a function. The function can both access them through formal parameters and the local arguments object.
array and object literals
    Like many scripting languages, arrays and objects (associative arrays in other languages) can each be created with a succinct shortcut syntax. In fact, these literals form the basis of the JSON data format.
regular expressions
    JavaScript also supports regular expressions in a manner similar to Perl, which provide a concise and powerful syntax for text manipulation that is more sophisticated than the built-in string functions.

Name: Anonymous 2008-12-24 13:25

>>4
I don't know why C-like syntax would be important, but Lua does all the rest (and does it better).

Name: Anonymous 2008-12-24 13:30

>>6
C-Syntax is this:
 abc(x,y,z){
if(x>0){y=do(x);if(!x){return y};
switch(y){
case 'what':;do_something();break;
default:
}}}

Name: Anonymous 2008-12-24 13:33

do
  local oldprint = print           -- Store current print function as oldprint
  print = function(s)              -- Redefine print function
    if s == "foo" then
      oldprint("bar")
    else
      oldprint(s)
    end
  end
end

can this be bracketised and run in lua or its FIOC?

Name: Anonymous 2008-12-24 13:35

this syntax sucks.Its mix of python and scheme

Name: Anonymous 2008-12-24 13:36

Lua:
do
end

what i want:
 oldprint = print         
 print = function(s)           
 if(s == "foo"){oldprint("bar")}else{oldprint(s)}

Name: Anonymous 2008-12-24 13:40

do
  local oldprint = print           -- Store current print function as oldprint
  print = function(s)              -- Redefine print function
    if s == "foo" then
      oldprint("bar")
    else
      oldprint(s)
    end
  end
end

OPTIMIZED :
oldprint=print;print=function(s);(s=="foo")?oldprint("bar"):oldprint(s);

Name: Anonymous 2008-12-24 13:48

FURTHER OPTIMIZED:
print(s=='foo'?'bar':s)

Name: Anonymous 2008-12-24 13:55

Lua:
function factorial(n)
  if n == 0 then
    return 1
  else
    return n * factorial(n - 1)
  end
end         

//notice the difference
Javascript:
function factorial(x){for(var i=x;i>0;i--){x=x*i};return x}

Name: Anonymous 2008-12-24 14:09

Lua:

fibs = { 1, 1 }                                -- Initial values for fibs[1] and fibs[2].
setmetatable(fibs, {                           -- Give fibs some magic behavior.
  __index = function(name, n)                  -- Call this function if fibs[n] does not exist.
    name[n] = name[n - 1] + name[n - 2]        -- Calculate and memoize fibs[n].
    return name[n]
  end
})

Javascript:
function fibs(x){a=0;b=1;c=0;for(i=x;i>1;i--){c=a+b;a=b;b=c}return b}

Name: Anonymous 2008-12-24 14:19

>>13
FIXED:
function factorial(x){for(i=x-1;i>0;i--){x=x*i}return x}

Name: Anonymous 2008-12-24 14:22

JavaScript could be more concise:like instead of:
function factorial(x){for(i=x-1;i>0;i--){x=x*i}return x}
i'd like to:
factorial(x){for(i=x--;i>0;i--){x*=i};x}

Name: Anonymous 2008-12-24 14:26

or even more concise:
fact(x)={loop(x--){x*=i};x}

Name: Anonymous 2008-12-24 14:31

fact(x)={loop(x--){x*=i};x}
----explained
function fact(x){
loop x-1 times
 multiply x by i(implicit loop counter) and save as x
return last expression;x
}

Name: Anonymous 2008-12-24 14:33

>>17
should be:
fact(x)={loop(x-1){x*=i}x}

Name: Anonymous 2008-12-24 14:42

Jvascript(shortest function to return absolute value)
function abs(x){return (x>0)?x:-x}

Could be twice as short:
abs(x){x>0?x:-x}

Name: Anonymous 2008-12-24 14:55

For every wasted character i could write more code.
Shorter code is more productive:thats why Lua,Python and other "Explicit declarational" languages suck.
They waste the space with empty syntax.

Name: Anonymous 2008-12-24 14:59

>>21
Bullshit.

Name: Anonymous 2008-12-24 15:01

The following expression finds all prime numbers from 1 to R. In both time and space, the calculation is O(R²).

(∼R∈R°.×R)/R←1↓ιR

Name: Anonymous 2008-12-24 15:02

>>23
Wtf is this language?

Name: Anonymous 2008-12-24 15:03

Name: Anonymous 2008-12-24 15:06

>>21
Enjoy your write-only, unmaintainable code.

Name: Anonymous 2008-12-24 15:07

: fact 1+ 1 tuck +do i * loop ;

Name: Anonymous 2008-12-24 15:53

>>13
Javascript:
function factorial(n)
{
    if (n == 0)
        return 1;
    else
        return n * factorial(n - 1);
}

--notice the difference
Lua:
function factorial(x)for i=1,x-1 do x=x*i end return x end

Name: Anonymous 2008-12-24 15:59

Uhh... isn't Javascript compiled these days?

Name: Anonymous 2008-12-24 16:00

>>28
end's and do's ruin the syntax
still the above recursive crap is never used in OPTIMIZED code.

Name: Anonymous 2008-12-24 16:01

>>29
the ngs compiler is linux only.
Java compilers make Javascripts into crappy java applets which load slower then original code and JVM to run.

Name: Anonymous 2008-12-24 16:03

>>28
Invisible block separators.Imagine such function 10 times larger.

Name: Anonymous 2008-12-24 16:05

function factorial(x)for i=1,x-1 do x=x*i end return x end
with separators.
//notice the difference
function factorial(x){for (i=1,x-1){ do x=x*i} end return x end}

Name: Anonymous 2008-12-24 16:09

>>32-33
What?  Why are you adding invalid characters?

Name: Anonymous 2008-12-24 16:21

>>34
They aren't invalid,they are what your crappy language should have
instead of end/do and.

Name: Anonymous 2008-12-24 16:27

to write code efficiently you need to utilize punctuation such as {(;)},not introducing code words you need to type each time you close the block of code.

Name: Anonymous 2008-12-24 16:32

>>36
Hello there, may I interest you in some APL?

Name: Anonymous 2008-12-24 16:34

>>35-36
do is faster to type than (){
end is faster to type than }

That other junk requires shift key combinations; with do and end you never leave the home row.

Name: Anonymous 2008-12-24 16:39

>>37
How does polar bear know what APLs is?

Name: Anonymous 2008-12-24 16:44

>>38
I have 2 hands.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List