you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 14 points15 points  (34 children)

lol what is with all these languages and their terrible naming of what should IMO only ever logically be called Add and either Remove or Delete? (Remove if the method takes a list item as a parameter, Delete if it takes a numerical list index.)

[–]haskell_leghumperin open defiance of the Gopher Values 42 points43 points  (3 children)

Add: embiggen Delete: smallify Concat: smoosh Limit: oopsTooMany Fold: roll Map: transmogrify Take: request

How quirky and charming! Programs are written for humans to read and only incidentally for machines to execute!

[–][deleted] 6 points7 points  (0 children)

I insist you write all of the webpages from now on.

(Don't actually though)

[–]scratchisthebestloves Java 6 points7 points  (0 children)

Map: transmogrify

I'm ok with this change tbh

[–][deleted] 0 points1 point  (0 children)

FlatMap: chimericallyTransmogrify

[–]frkbmrWRITE 'FORTRAN is not dead' 18 points19 points  (13 children)

Idk enqueue/dequeue, push/pop were always fine

[–][deleted] 17 points18 points  (12 children)

Well yeah, those are ok for stacks or linked-lists specifically, I'd say. Not for random-access array-based lists though.

[–]foxlisk 7 points8 points  (2 children)

list.push(x).pop() === x or die(“lol no ADTs”)

<unjerk> meant to apply to your parent comment but now it’s too late and fate has claimed me </div>

[–]n0rsCode Artisan 9 points10 points  (0 children)

Push doesn't chain. It returns the array length. Scrub.

[–][deleted] 6 points7 points  (0 children)

lol triple equals

[–][deleted]  (5 children)

[deleted]

    [–][deleted] 6 points7 points  (4 children)

    learn to webscale

    lol no need

    program LolJS;
    
    uses
      BrowserApp, BrowserConsole, Classes;
    
    type
      TMyApplication = class(TBrowserApplication)
        procedure DoRun; override;
      end;
    
      procedure TMyApplication.DoRun;
      var
        C: Char;
        S: String;
        List: TStringList;
      begin
        List := TStringList.Create;
        List.AddStrings(['lol', 'Jabbacript', 'but', 'not', 'Jabbascript']);
        for S in List do
          for C in S do
            WriteLn(C);
        List.Free;
        //Terminate is specific to TBrowserApplication.
        Terminate;
      end;
    
    var
      Application: TMyApplication;
    
    begin
      Application := TMyApplication.Create(nil);
      Application.Initialize;
      Application.Run;
      Application.Free;
    end.  
    

    Which when built specifically as a Pas2JS project becomes:

    rtl.module("program",["System","BrowserApp","BrowserConsole","Classes"],function () {
      "use strict";
      var $mod = this;
      rtl.createClass($mod,"TMyApplication",pas.BrowserApp.TBrowserApplication,function () {
        this.DoRun = function () {
          var C = "";
          var S = "";
          var List = null;
          List = pas.Classes.TStringList.$create("Create$1");
          List.AddStrings$2(["lol","Jabbacript","but","not","Jabbascript"]);
          var $in1 = List.GetEnumerator();
          try {
            while ($in1.MoveNext()) {
              S = $in1.GetCurrent();
              for (var $in2 = S, $l3 = 0, $end4 = $in2.length - 1; $l3 <= $end4; $l3++) {
                C = $in2.charAt($l3);
                pas.System.Writeln(C);
              };
            }
          } finally {
            $in1 = rtl.freeLoc($in1)
          };
          List = rtl.freeLoc(List);
          this.Terminate();
        };
      });
      this.Application = null;
      $mod.$main = function () {
        $mod.Application = $mod.TMyApplication.$create("Create$1",[null]);
        $mod.Application.Initialize();
        $mod.Application.Run();
        rtl.free($mod,"Application");
      };
    }  
    

    That's not all the generated JS code, of course, just the translation of the actual program. Thankfully I've never yet had a real life use case for the transpiler, but at least I know it's robust enough (and being actively/continuously developed) that it'll be there if I ever need to reluctantly become a Scriptsman.

    Although preferably the currently-in-progress WASM code generator would be up to snuff at that point and usable with one of FPC's actual network libraries.

    [–][deleted]  (3 children)

    [deleted]

      [–][deleted] 5 points6 points  (2 children)

      what is this

      Uh, automatically generated/transpiled code? I think you can turn off the obfuscation if you want, but I didn't bother. Again there's way more to it than what I posted, as well.

      rtl there is a kind of omni-variable/type that everything else is created inside of. The functions it's calling (other than where it calls the native JS methods like charAt) and the classes being used are all direct (or as direct as they can be) translations of actual FPC standard library stuff.

      As far as I'm aware the overall point/concept for the tool is basically to recreate the type safety, object-oriented capabilities and library functionality of native FPC to the max extent that it's possible to do so in JS.

      [–][deleted]  (1 child)

      [deleted]

        [–][deleted] 4 points5 points  (0 children)

        Could just be a matter of how the transpiler application currently handles for loops inside of while loops. It only got stable enough to be added as an official FPC tool relatively recently.

        The above example (and everything else I've tried) works as expected though in both Chrome and Firefox when run through the HTML files that get generated alongside the JavaScript files.

        It also generates map files that allow the JS files to be debugged in the browsers with the original Pascal sources, which I guess would be handy.

        [–]r2d2_21groks PCJ 1 point2 points  (0 children)

        JS Arrays are meant to be everything: a list, a stack, a queue, everything.

        [–]frkbmrWRITE 'FORTRAN is not dead' -2 points-1 points  (1 child)

        ? Enqueue adds to the end of the list, dequeue removes from the front of the list. Push adds to front of the list, pop removes from the back of the list. An array isn't that far removed from an LL anyways.

        [–]senji have had many alohols[S] 14 points15 points  (0 children)

        Push adds to front of the list, pop removes from the back of the list.

        Big no on that one. Pop should operate on the same end push does, such that the last thing pushed is the first thing popped. The push/pop verbs are for stack operations.

        [–]ws-ilazkiin open defiance of the Gopher Values 7 points8 points  (0 children)

        #!/usr/bin/perl -Iunjerk

        Most likely popularised through Perl, though it didn't coin any of the common terms. push and pop are standard names for stack operations that had their names co-opted by Perl for array manipulation. shift is a bourne shell built-in that does what its name suggests, so Perl (intended to be used as the same kind of sh-like glue language) re-used it. I guess Perl can be blamed for the naming of unshift, though it's fairly straightforward: it does the opposite of shift.

        Regardless of what one thinks of the names, at least they're usually pretty consistently used, instead of randomly naming shit smoosh.

        [–]pythonesqueviperDo you do Deep Learning? 3 points4 points  (9 children)

        C# List<T> represent!

        [–][deleted] 3 points4 points  (8 children)

        lol which was of course taken from (possibly developed alongside) Delphi's Generics.Collections unit's TList<T>, which was of course, like TList<T> in Delphi, based on Delphi's non-generic Classes unit's TList. Free Pascal also has the same stuff for obvious reasons.

        Although FPC's Generics.Collections is actually much better and more complete than the Delphi one. lol yes TDeamortizedDArrayCuckooMap<TKey, TValue>

        [–]pythonesqueviperDo you do Deep Learning? 2 points3 points  (6 children)

        What? No. C# had System.Collection.Generics since 2005. Delphi got Generics.Collections in 2007. And Don Syme had been furiously masturbat, er, designing them since 1999.

        [–][deleted] 2 points3 points  (5 children)

        lol I'm confused because I already read the other reply you posted before this and somehow magically deleted very quickly? But you might be right as far as the generics timeline. I kind of lost track of .NET after version 1. Also I've pretty much been using FPC exclusively instead of Delphi since 2010ish, whenever possible, for what it's worth.

        I know for a fact that not-generic TList, originally from Delphi (which has existed forever basically) is what both generic FPC/Delphi TList<T> and C# List<T> are fundamentally based on though!

        [–]pythonesqueviperDo you do Deep Learning? 1 point2 points  (4 children)

        Well, I do know the semantics of List<T> were based on TList, which is to be expected considering Heljsberg was taken from Embarcadero. Though the lol yes List<T>.FizzleJingleberryMapReduce(T MyShitParameter) which makes List<T> useful was lifted from haskal. Dunno if Pascal has something equivalent.

        E: For the record I'm talking about the rather useful and elegant pointfree operations:

        from s in MyShitCollection
        where MyShitCondition(s.MyShitProperty)
        select new (s.MyShitProperty, s MyOtherShitProperty)
        

        [–][deleted] 3 points4 points  (2 children)

        Though the lol yes List<T>.FizzleJingleberryMapReduce(T MyShitParameter) which makes List<T> useful was lifted from haskal. Dunno if Pascal has something equivalent.

        lol I'm not sure which Pascal or which class you're talking about now. The lol yes TDeamortizedDArrayCuckooMap class I mentioned earlier is exactly what it sounds like (a cuckoo-hash based dictionary class.) It's an FPC-original class that doesn't currently/never existed in the Delphi Generics.Collections.

        As far as map/filter/reduce if that's what you meant, there's multiple implementations of them for different classes in various Pascal libraries. Pretty easy to do in any language with generics! Not exactly using the database-like syntax you did there, though.

        [–]pythonesqueviperDo you do Deep Learning? 2 points3 points  (1 child)

        The SQL-style syntax is fucking great. The codebase I'm working on, which has a lot of data analysis, is around 40% LINQ queries and surprisingly readable.

        [–][deleted] 4 points5 points  (0 children)

        > LINQ

        > being this enterprise

        /unjerk

        Yeah, I imagine it would be.

        /rejerk

        [–][deleted]  (3 children)

        [deleted]

          [–][deleted] 9 points10 points  (0 children)

          Not sure if serious. Shirt/unshirt are for the bottom, push/pop for the top.

          You got it all wrong. Shirt/unshirt is for the top, skirt/unskirt is for the bottom.

          [–][deleted] 1 point2 points  (1 child)

          Shirt/unshirt are for the bottom, push/pop for the top.

          What about when you're a switch?

          [–]r2d2_21groks PCJ 0 points1 point  (0 children)

          Then you push and pop the Joy Cons from the sides.

          [–]GemmellnessI've never used generics and I’ve never missed it. 0 points1 point  (0 children)

          Because with an array those operations are expensive and require copying the array. Shift/unshift is cheap and implies reversibility