An improved version of GolfScript

12

6

I am planning to write an improved GolfScript for even shorter programs that can do more things. This is not a challenge; it is a request for feedback and tips on what I should do. (see tags)

I'm not sure if this should be Community Wiki. If you think so, just flag for a moderator to convert it :)

This language will be very similar to GolfScript. It is still written in Ruby. However, it has a few differences:

  • Using ` as a string delimiter, because it's an uncommon character, so less escaping will be needed. (Another character can replace its function, like # (more on that later)). \` to escape a backtick, \\ to escape a backslash, and there are no other escape sequences. If you need a newline, just stick an actual literal newline in the string.
  • Using Ruby's Rationals for arbitrary precision floating point, one of GolfScript's major flaws.
  • The ability to convert types to other types. For example, you can convert a block to a string.
  • Regular expressions. Probably created with "...". Operators will be overloaded for them as well. For example, "\W"~{`Invalid: non-word character`}{`OK`}if. Will automatically execute when pushed from a variable, like blocks.
  • File and Date objects, to do more stuff that was impossible in GolfScript. These will not have literals, but will have functions for initializing them, such as `file.txt`fl (name of the file-making-function may change).
  • Hashes maybe, but I'm not sure on that one. Should I?
  • Helper functions to do even more. For example, `http://example.com`net for network access (again, net operator may be renamed). rb to execute a string as Ruby code. There will be many more of these; suggestions welcome.
  • No comments, so that # can be used for something else. If you want a comment, `comment here`; will work fine. (Maybe # can replace `'s function)
  • It will be completely rewritten in a way that it will be much easier to add functions. Basically, the code will be more readable. (Have you seen the GolfScript source? :/)
  • It will be on Github so it can be collaboratively worked on. I'll license it under MIT or something.
  • No final newline, so cheaty quines work :P

And I'm setting these apart because I think they're the most drastic and helpful changes (except maybe adding floating point):

  • It will have many Ruby functions built-in. For example, shuffle (which may be abbreviated to sf) (previously took 9 characters), tr (previously 14 chars), sample (sm, previously .,rand=), flatten (fl, previously ???), etc.
  • It will be mushed, like Rebmu. For example, now you can do ~:a0<{0a-}aIF (using a letter variable name) instead of ~:$0<{0$-}$if (overwriting the sort function). (example from here). Note that this way, it is case-insensitive, and numbers are not allowed in variable names. This is okay in my opinion since it's a golfing language :P
  • It will have debugging. I will add the ability to supply a flag specifying array delimiters, element delimiters, etc., number output (rational, float, or int?), stepping through instructions one at a time, tokenizing and outputting each token instead of running the program, etc.

So, my question is: what is there to improve? What do you think I should add?

Any other ideas for this, before I start coding it?

Doorknob

Posted 2013-12-31T18:58:15.527

Reputation: 68 138

Question was closed 2015-10-18T09:04:29.053

Questions like this are no longer considered a good fit for the site, so I'm closing this.

– Martin Ender – 2015-10-18T09:04:23.000

@MartinBüttner Good call. Think we should lock it as well? – Doorknob – 2015-10-18T12:03:37.090

Do realize that if you add mushing you lose case sensitivity. – marinus – 2013-12-31T19:03:19.617

@marinus I realize that. I should have made that clear; editing... – Doorknob – 2013-12-31T19:04:23.977

Also what it really needs is a way to do explicit I/O (for interactive programs). The interpreter could check beforehand if the program uses explicit I/O, and only do implicit I/O if it doesn't. – marinus – 2013-12-31T19:05:40.410

@marinus Great, you should add that as an answer then :) – Doorknob – 2013-12-31T19:06:09.060

` is already a quite important operator, thus not good as string delimiter. – Howard – 2013-12-31T19:10:18.260

@Howard I was planning on replacing \`` with#` or some other character. I'll edit that also – Doorknob – 2013-12-31T19:13:17.883

But I still have a need for comments! Otherwise you cannot save comments with your code. – Howard – 2013-12-31T19:14:22.057

@Howard \comment here`;` will work. I just don't see the need for comments in a golfing language... – Doorknob – 2013-12-31T19:15:39.680

``comment here; will be interpreted while comments are not. What about strings in the comment? Or #{}? – Howard – 2013-12-31T19:18:37.423

Related: Language idea for golfing purposes

– Peter Taylor – 2013-12-31T19:19:15.957

@Howard Good point. I could add a rb command instead of #{}, and I guess you'll just have to escape \``. (Use`\``` for backtick in comments :-P) – Doorknob – 2013-12-31T19:19:46.103

Escaping inside comments? That sounds very strange. What's wrong with " as string delimiter? – Howard – 2013-12-31T19:20:52.683

@Howard, I sometimes do multi-line comments as 'comment';, but it is slightly fragile because it's possible to use ' in the comment unintentionally. – Peter Taylor – 2013-12-31T19:21:04.947

@Howard " is used more often, and would require an extra char to escape. Yes escaping in comments is odd, but it is a golfing language :-P – Doorknob – 2013-12-31T19:22:28.773

No no no ;-) If you'd post the first one as answer I'd downvote it. – Howard – 2013-12-31T19:38:10.973

Ok, I have to go on a plane so I'll not comment for a while. Looking forward to ideas when I land! :-) – Doorknob – 2013-12-31T19:44:46.400

Any updates on this? I've thought about upgrading Golfscript myself. Will try to remember some ideas I had and post them. – Claudiu – 2014-03-30T02:55:34.887

1@Claudiu My development on my new language is quite alive, although I've recently been fairly busy so I haven't done much with it for a little while. Some of these ideas are just not good ideas though, which I am not using :P – Doorknob – 2014-03-30T03:01:44.113

Answers

17

Flexible I/O

Golfscript cannot at present be used for interactive programs. I propose some functions for explicit input be added (i.e. readline, getchar and friends). The interpreter should see if the program uses these before running it.

If the program does not call any input functions, the interpreter should act like Golfscript normally does.

I wouldn't expect the interpreter to detect input functions in eval'ed code generated at runtime, but if it somehow can do that, kudos.

marinus

Posted 2013-12-31T18:58:15.527

Reputation: 30 224

This is a great idea; limited io is one of golfscript's large limitations. +1 – Doorknob – 2013-12-31T19:16:29.540

11

Shorter built-ins

Single-character aliases for all of the built-in commands which don't have them. I would use base a lot more if it were just B.

Peter Taylor

Posted 2013-12-31T18:58:15.527

Reputation: 41 901

But what if you use b as a variable name? Still; good idea; you just remember to not use that name if you're going to use the function, and if you aren't using the function, then it doesn't affect you at all. – Doorknob – 2013-12-31T19:24:53.130

@DoorknobofSnow, you can already use built-ins (and even tokens such as ^ or $) as variable names. It doesn't make that problem any worse. Besides, I suggested aliases to allow backwards compatibility, so you would just have to use the longer name if you'd assigned something else to the shorter alias. – Peter Taylor – 2013-12-31T19:26:31.283

4Z for zip would also be very useful. – Howard – 2013-12-31T19:29:55.677

Maybe we can release an official standard library for GolfScript. But I am unclear about how it can be included in solutions (missing #include and "#{IO.read'lib'}"~ is too long). – Howard – 2014-01-01T07:41:37.630

@Howard Now that's an idea... I could add libraries into my language, maybe like mylang -Llibname somefile.ext. – Doorknob – 2014-01-01T13:39:46.333

9

Combined div-mod

This is a bit more niche than some of the suggestions, but when working on number-theoretic programs I frequently find myself wanting an operation which pops two integers a and b from the stack and pushes a/b and a%b. (At present this is 1$1$/@@%).

Peter Taylor

Posted 2013-12-31T18:58:15.527

Reputation: 41 901

Since it's so niche, maybe something like dvm for DiV-Mod. Thanks for all the ideas :-) +1 – Doorknob – 2013-12-31T23:52:28.477

8

Numbers

Change the lexer such that leading 0 is not part of a number:

# current behaviour
01     # -> 1

# new
01     # -> 0 1

Also negative numbers should be written with _ instead:

# current behaviour
1 2-3   # -> -1 3

# new
1 2_3     # -> 1 2 -3

Howard

Posted 2013-12-31T18:58:15.527

Reputation: 23 109

Wow, that's interesting. Usually you don't typically push two numbers in a row, but this would help with that a lot. The negative thing is great too, instead of 0 100- for negative 100. +1 – Doorknob – 2013-12-31T19:30:43.847

1I've thought about this before. There shouldn't be any support for negative integer literals at all. It's already handled by ~. E.g. -1 is 0~. This makes a small number of numbers longer by one char, but removes the moderately frequent need for whitespace after -. – Peter Taylor – 2013-12-31T19:33:52.330

Wait a minute, how would you push, for example, 1001? I think you meant leading zero, not trailing. – Doorknob – 2013-12-31T19:33:55.613

@DoorknobofSnow Right. – Howard – 2013-12-31T19:39:33.573

What would you think about doing {0\-}:~; (~ negative-izes a number) and using not for bitwise (just like and or xor)? – Doorknob – 2014-01-01T01:22:08.133

@Doorknob, bad idea. You lose the overloads; not sounds more like an alias for !; and it doesn't even gain consistency because and or aren't bitwise. – Peter Taylor – 2014-01-01T08:35:15.400

@Peter Well, I meant while still keeping the other overloads, but yes, it is probably a bad idea. Okay, I won't do that – Doorknob – 2014-01-01T13:35:42.250

@Howard: That's not the current behavior. 1 2-3 # -> 1 2 -3 – Dennis – 2014-05-06T18:04:45.473

@Dennis Of course you're right. With hindsight I might have meant that I want it that way to save a space if - is not treated as sign but always as operator (and '_' as sign). – Howard – 2014-05-07T11:27:17.127

8

Access to the whole stack

GolfScript is a stack-based language, but access to all but the top three items on the stack is limited to <integer>$ to copy the nth item. It would be useful to have something like PostScript's roll command so that it's easier to work with more than three "live" variables.

Ideally there would be one-arg and two-arg versions, but if there aren't enough names around then the one-arg should get preference for a one-character one.

The one-arg one just takes the number of items to roll. E.g. 1 roll does nothing; 2 roll is equivalent to \; 3 roll is equivalent to @; 4 roll and for higher numbers doesn't have an existing equivalent; the closest that's possible is something like

]-4/()\+\+[]*-1%~

(and that doesn't even handle non-integers at certain positions on the stack, or active [, and almost certainly breaks inside loops too).

The two-arg one also takes an amount to roll; a b roll2 is equivalent to {a roll}b*.

Peter Taylor

Posted 2013-12-31T18:58:15.527

Reputation: 41 901

So, like Ruby's rotate. You should edit this into the CW answer. – Doorknob – 2013-12-31T23:54:38.140

@Doorknob, no. I'm talking about operating on a slice of the stack, not on an array. – Peter Taylor – 2014-01-01T08:41:23.493

Umm...I'm not sure what you mean. I'm not familiar with postscript, but roll just rotates the array, right? – Doorknob – 2014-01-01T13:37:08.960

@DoorknobofSnow, stack. An array is an item which goes on the stack. – Peter Taylor – 2014-01-01T14:10:38.870

Oh, so it rotates the whole stack. Ah, that might be useful! +1 – Doorknob – 2014-01-01T14:32:04.717

@DoorknobofSnow Doesn't rotate the whole stack but only part of it, namely the top a items. – Howard – 2014-01-01T14:36:12.777

@Doorknob I've got a pretty full explanation of postscript's roll operator over on SO

– luser droog – 2014-03-30T06:50:17.860

8

CJam

I have implemented "an improved GolfScript" and it is called CJam - http://sf.net/p/cjam
Now at the second release (version 0.6) it already has many if not most of the features discussed here. I'll try to list them:

  • still written in Ruby - nope, java
  • using ` as a string delimiter - no, but it uses double-quoted strings with minimal escaping (\ escapes only \ and ")
  • floating point - supported, but only standard "double", not arbitrary precision
  • convert types to other types - yes
  • regular expressions - not yet, but planned; will use regular strings with special operators
  • File and Date objects - no, but can get the current date/time
  • hashes - assuming those are like python dicts or java maps, then they're not supported (may consider in the future)
  • helper functions to do even more - yes, a lot
  • `http://example.com`net - "example.com"g
  • execute a string as Ruby code - nope
  • no comments - exactly, # used for something else, "comments like this";
  • easier to add functions - I think so, but I'm also biased :)
  • on Github - even better (in my opinion, please don't shoot) - on SourceForge, using hg
  • licensed under MIT - yes
  • no final newline - right
  • shuffle - mr
  • tr - er
  • sample - not done, _,mr=
  • flatten - not done, but probably easier to achieve
  • mushed - nope, but identifiers don't need to be separated
  • debugging - only stack traces, and ed operator for showing the stack

  • flexible I/O - yes, but only explicit input

  • shorter built-ins - yes, b = base, z = zip
  • separate leading 0 - no, but can use predefined variables
  • disambiguate - - yes, but not with _; 1 2-3 -> 1 2 -3; 1 2m3 -> -1 3
  • roll/rotate the stack - nope
  • array set - t
  • divmod - md
  • change the lexer (for identifiers) - yes, more below
  • cartesian product - not exactly the same, but yes, m*
  • unicode operators - no
  • single-character identifiers - predefined operators have 1 or 2 characters and variables are single-character uppercase letters; they can all be concatenated without confusing the lexer/parser
  • operators on blocks - no
  • stable sort - yes
  • turn symbols back into code blocks - no, but may add later
  • current date/time - et
  • command line args - ea
  • clearly separating built-ins - yes, but capitals are variables; built-ins are or start with lowercase and special characters
  • min and max - yes, currently only for 2 values: e<, e>
  • absolute value - z (GolfScript has abs, not lacking)
  • sum and product of an array - :+, :*
  • Manhattan distance - nope
  • chr - c (converts to a character, not a string)
  • spill a string onto the stack - CJam strings are made of characters, not numbers; to spill the characters it's still {}/
  • a version of : that consumes what is stored - nope
  • operators for >=, <= - nope, use <!, >!
  • base64 and zlib - nope
  • shortcuts for 1$, 2$, 3$, 4$, 5$ - nope
  • copy the top two stack items - planned; for now use 1$1$
  • local variables - nope
  • HQ9+ features - no, thank you

CJam has a lot more features, check out https://sourceforge.net/p/cjam/wiki/Operators/

aditsu quit because SE is EVIL

Posted 2013-12-31T18:58:15.527

Reputation: 22 326

7I disagree with SourceForge and Mercurial being better than GitHub. – nyuszika7h – 2014-05-02T10:44:11.613

1@nyuszika7h it's ok, we all have our preferences – aditsu quit because SE is EVIL – 2014-05-02T11:19:31.760

I just posted my very first CJam answer, because my GolfScript answer was in desperate need of a proper sqrt function. CJam is a lot faster than GolfScript!

– Dennis – 2014-05-22T00:38:28.857

@Dennis Awesome :) – aditsu quit because SE is EVIL – 2014-05-22T01:03:28.030

@aditsu Would you consider CJam a dialect of GolfScript or a new language inspired by GolfScript? (Here's the reason I'm asking: http://codegolf.stackexchange.com/questions/37464/write-a-polyquine#comment86644_37464)

– Martin Ender – 2014-09-15T15:07:27.130

@MartinBüttner I consider it a new language inspired by GolfScript. I'm curious about that quine, I know a 9-char one that has different syntax in the 2 languages. – aditsu quit because SE is EVIL – 2014-09-15T18:50:17.773

6

Change the lexer

GolfScript's lexer treats a Ruby identifier (anything which matches the regex [_a-zA-Z][_a-zA-Z0-9]*) as a single token. If it instead treated [a-zA-Z]+ as a token that would free up _ to be a built-in and would allow an alpha variable to be followed by a literal integer without separating whitespace.

Peter Taylor

Posted 2013-12-31T18:58:15.527

Reputation: 41 901

Well, currently I'm using simply [a-z]+|[A-Z]+, for the mushing, so underscore is free. This is an interesting and very unique idea though! +1 – Doorknob – 2013-12-31T19:27:11.907

5

Unicode aliases

Multiple-character commands could have unicode aliases. This would save on the score when the score is counted in characters and not in bytes.

marinus

Posted 2013-12-31T18:58:15.527

Reputation: 30 224

7uh... we don't want another APL... – John Dvorak – 2013-12-31T19:40:21.833

1Golfscript isn't anything like APL, Unicode or no. We already have several other APLs, like J and K. (or even R which looks quite APL-inspired to me, to the point that you can do literal translations quite often) – marinus – 2013-12-31T19:54:39.633

The distinguishing point about APL is that it uses a very different charset than anything else, not that it uses vector arithmetic natively. I like J, I use it, and I commonly upvote J answers. I've yet to upvote one APL answer. If I wanted to paint my programs instead of writing them, I'd use Piet. – John Dvorak – 2013-12-31T19:57:43.263

I think APL is more legible than J, certainly more legible than Golfscript. – marinus – 2013-12-31T20:06:52.140

5

Stable sort

The $ builtin on blocks should perform a stable sort.

Howard

Posted 2013-12-31T18:58:15.527

Reputation: 23 109

5

Array set operator

["A" "B" "C" "D" "E" "F"] -1 4 S    # -> ["A" "B" "C" "D" -1 "F"]

Any built-in we can make available for that?

Howard

Posted 2013-12-31T18:58:15.527

Reputation: 23 109

+1 I started writing a blog post about implementing array set, but never finished it. It's currently extremely hard in full generality. This would make a big difference to some challenges. – Peter Taylor – 2013-12-31T23:33:08.683

I can't believe this isn't built in to golfscript already. +1 – Doorknob – 2014-01-01T01:13:35.037

5

Single-character identifiers

It's not like a code golf solution is going to have too many variables. And it would save on spaces.

James Wood

Posted 2013-12-31T18:58:15.527

Reputation: 406

Hmm.. This could also be done by changing the parser. Perhaps a flag to specify this behavior? Great idea! +1 – Doorknob – 2014-01-01T16:09:46.223

4

% as builtin for product

[1 2][1 2 3]%  # -> [[[1 1][1 2][1 3]][[2 1][2 2][2 3]]]

Howard

Posted 2013-12-31T18:58:15.527

Reputation: 23 109

+1; you could edit my CW answer and add this one – Doorknob – 2013-12-31T22:45:08.747

What about modulo? – MilkyWay90 – 2019-05-24T21:10:35.260

3

Regex support

The lack of regex support has always struck me as odd in a language designed for golfing. It would be great to have

  • <string> <string> <string> y (aka tr, using Perl's one-char alias for it)
  • <string> <string> <string> s (substitute)
  • <string> <string> <block> s (substitute with callback)
  • <string> <string> m (match)

Peter Taylor

Posted 2013-12-31T18:58:15.527

Reputation: 41 901

I already mentioned regex in my question. – Doorknob – 2013-12-31T19:31:28.850

3

Builtins for current date/time

It is currently very quirky to get date/time using Ruby evals.

D     # -> [2013 12 31]
T     # -> [23 59 59]

Howard

Posted 2013-12-31T18:58:15.527

Reputation: 23 109

Does that give date/time in Lima or Zulu? – Peter Taylor – 2013-12-31T19:55:58.233

@PeterTaylor Don't know - times are changing ;-) – Howard – 2013-12-31T19:56:55.330

@howard Did you mean, "The times, they are a-changing "?

– John Dvorak – 2013-12-31T19:59:56.073

Already mentioned as the Time type in the OP. – Doorknob – 2013-12-31T22:47:54.710

3

Make |, & and ^ built-ins do something useful on blocks

E.g. <array/string> <block> | can be used as index function

[0 -10 -20 30 40 -50 60] {0<} |   # -> [1 2 5]

Any ideas for <array/string> <block> & or <array/string> <block> ^?

Howard

Posted 2013-12-31T18:58:15.527

Reputation: 23 109

What does array block = do now? – John Dvorak – 2013-12-31T20:19:05.870

@JanDvorak Compare. Useful if you want to compare a string to a block, e.g. "0<" {0<} =. – Howard – 2013-12-31T20:20:08.903

How often do you need that? I'd rather drop that, and use array block = for "select by predicate" – John Dvorak – 2013-12-31T20:28:31.143

@JanDvorak select by predicate is already implemented using ,. – Howard – 2013-12-31T20:29:27.533

oh, never mind. Go on :-) – John Dvorak – 2013-12-31T20:29:55.747

Nice idea. Lol, I thought golfscript overloaded everything already :-P +1 – Doorknob – 2013-12-31T22:44:20.680

2

A way to turn symbols back into code blocks

Currently, we can bind code blocks to symbols with :, but there's no way to reverse the process: executing a symbol bound to a code block just executes the block.

I can see a couple of ways to implement this:

  1. add new syntax, e.g. #foo to push the value of foo to the stack, even if it's a code block, or

  2. add an operator to expand every symbol in a code block, so that (using _ as the new operator), e.g. {2*}:dbl; {dbl dbl}_ would produce {2* 2*}.

I can see advantages to both methods. The latter could substitute for the former, at the cost of two extra chars ({foo}_ instead of #foo), but I can see some potential applications for the former syntax where those two chars would be prohibitive (e.g. using array #func % instead of array {func} %).

Meanwhile, the former syntax could be used to replace the latter if there was a convenient way to somehow iterate over the tokens in a code block (which could be useful on its own, anyway).


In either case, I'd propose that expanding symbols that are bound to native built-ins (i.e. implemented in Ruby code) should return some kind of stub that could be called to obtain the functionality of the built-in, while being either impossible or just unlikely to be overridden. For example #$ (or {$}_) could return e.g. {builtin_dollar}, where builtin_dollar would contain the actual implementation of the $ built-in (and #builtin_dollar or {builtin_dollar}_ should just return {builtin_dollar} itself).

This would allow built-ins to be redefined without losing access to their functionality (see my earlier suggestion), so that if I, say, for some reason wanted to swap the meanings of $ and @, I could just do #$ #@ :$; :@; (or {$}_ {@}_ :$; :@;).

Ilmari Karonen

Posted 2013-12-31T18:58:15.527

Reputation: 19 513

One detail I'm not sure of is what the _ operator should do if the code block contains variable assignments. The obvious thing would be to just leave any :symbol tokens untouched and expand anything else, but this would cause _ to break any code using local variables. Making it not break such code might be impractically complicated, though. – Ilmari Karonen – 2014-01-01T18:00:54.020

1Your second version would fit together with an flatten operator on arrays: [[1] [2] [3]] _ -> [1 2 3]. – Howard – 2014-01-01T18:04:02.357

So what would be the result of 2:A;{1:A;A}_? – Howard – 2014-01-01T18:06:14.430

Naïvely, {1:A;2} (or, to be technical, {1:A builtin_semicolon 2} if the built-in expansion feature was included). If some kind of "local variable exclusion" feature was included, it might plausibly evaluate to just {1:A;A}. – Ilmari Karonen – 2014-01-01T18:09:21.237

Or to be even more technical {builtin_1 :A builtin_semicolon 2}. – Howard – 2014-01-01T18:17:48.777

Possibly, although I'd be inclined to leave numbers and whitespace (and strings!) alone. If you redefine them, you deserve all the pain you'll get. – Ilmari Karonen – 2014-01-01T18:24:04.180

Still struggling with your example: it should read {2*}:dbl; {dbl dbl}_ -> {{2*} {2*}}, shouldn't it? – Howard – 2014-01-01T18:26:09.577

No, if {dbl}_ evaluates to {2*}_, then {dbl dbl} should evaluate to {2* 2*}, while {{dbl} {dbl}}_ should become {{2*} {2*}}. – Ilmari Karonen – 2014-01-01T18:28:43.507

That would mean that you expand symbols deep into code-blocks? – Howard – 2014-01-01T18:36:26.243

Yes; I didn't state that explicitly in my post above, but I think that'd be the right thing to do, especially given that code blocks appear so often in looping constructs like array {loop} % where there's little distinction between the code inside and outside the block, except for the number of times it is executed. – Ilmari Karonen – 2014-01-01T18:39:45.140

Hmm, maybe just [some character]varname to push instead of execute, implemented on regex too. Good idea! +1 – Doorknob – 2014-01-01T18:42:03.123

+1, but only for the _ version ;-) – Howard – 2014-01-01T18:42:04.487

1

Variable preset with command line args

Unfortunately, there isn't any char left unassigned, but maybe we can use A for that?

Howard

Posted 2013-12-31T18:58:15.527

Reputation: 23 109

_ is available. Perhaps that? Anyway, yes, golfscript needs a way of taking cmd line args +1 – Doorknob – 2013-12-31T22:45:47.407

0

Native Ruby functions that I should implement

This is Community Wiki; feel free to edit and add the functions you think I should implement!

Format: "nativeFunctionName (nameInMyLanguage)"

  • shuffle (sf)
  • tr (tr)
  • sample (sm)

Doorknob

Posted 2013-12-31T18:58:15.527

Reputation: 68 138

0

Take features from APL and HQ9+ too!

  • Shortcuts, like in APL. EDIT: just saw the answer "unicode aliases". That's what I meant :)
  • Other golf-oriented shortcuts, like in H9+, HQ9+, CHIQRSX9+

xem

Posted 2013-12-31T18:58:15.527

Reputation: 5 523

Okay, so how would you propose that? Any specific ideas? – Doorknob – 2013-12-31T19:17:50.107

unicode characters allowing to do complex things in just one character. – xem – 2013-12-31T19:19:38.510

@Doorknob of Snow , I updated my answer with the shortcuts I'd like to see: those from APL, and those from CHIRQSX9+ :) – xem – 2013-12-31T19:25:21.253

Hmm, the hq9+ thing seems too cheaty :-P – Doorknob – 2013-12-31T19:25:50.260

It's golf oriented :P im my opinion your language should do at least as well :) – xem – 2013-12-31T19:27:26.777

0

Clearly separating built-ins

e.g. capitals : built-ins ; making B for base feasable

user11485

Posted 2013-12-31T18:58:15.527

Reputation:

1As mentioned above there is no need to separate. If someone likes to overwrite a builtin he should be able to do so. I even found useful applications of overwriting operators like {-}:+. – Howard – 2013-12-31T20:18:20.363

No need, also this language will be case insensitive. – Doorknob – 2013-12-31T22:47:19.270

2Since the goal is to provide less strokes per hole, having case sensitivity and more built-ins effectively leads towards the mission statement. – None – 2014-01-01T03:50:19.090

0

Local variables / closures

One thing I really miss in GolfScript is the ability to temporarily change the value of a symbol.

In particular, there's currently no way to temporarily override the meaning of a "primitive" built-in: once you, say, redefine $, you're never going to sort anything in that program again. (Well, not without writing your own sort implementation, at least.) It would be really nice to be able to say, for example, that in this code block $ means something else, but still keep the normal meaning elsewhere.

Related to the above, it would be nice to bind symbols in a code block to their current value. Sure, I can write, say, {$-1%}:rsort and be able to use rsort to sort and reverse an array, but that works only as long as the definition of $ (or -1 or %) doesn't change, since my rsort function is still calling the global symbol $. It would be nice to be able to say "let rsort do what $-1% currently does, even if those symbols are later redefined."

In particular, the standard library could use this kind of binding. It's kind of surprising to realize that, say, changing n changes the behavior of puts, or that redefining ! completely messes up xor. (Then again, some caution should be exercised here, since, in particular, the ability to change the behavior of puts turns out to be turns out to be the only way to avoid printing a final newline in the current version of GS.)

Edit: Being able to turn symbols back into code blocks would go a long way towards implementing this functionality. In particular, the {foo}_ syntax suggested in that answer would effectively perform one level of static binding by expanding all symbols in a code block. Combine that with a fixpoint combinator for deep static binding, and Bob's your uncle...

Ilmari Karonen

Posted 2013-12-31T18:58:15.527

Reputation: 19 513

"let rsort do what $-1% currently does, even if those symbols are later redefined" So Emmental? – CalculatorFeline – 2016-03-07T03:29:39.453

Come on - all the fancy new languages celebrate lazy evaluation ;-) Let's keep that feature in GolfScript. – Howard – 2014-01-01T17:09:00.750

On second thought - you're right, it is more a feature of binding than evaluation. But then - static binding is more complex than it sounds - e.g. provide recursive calls inside a definition. – Howard – 2014-01-01T17:16:40.190

0

More built-in functions

Make all the single-letter variables a-z and A-Z perform some generic, useful function. Some built-ins that are lacking:

  • min and max: all or some of top 2 stack values, top n stack values, over an array
  • absolute value
  • sum and product of an array. why do {+}* when you can do S? You have 52 functions to work with here!
  • Manhattan distance (i.e. x1 y1 x2 y2 --> abs(x2-x1)+abs(y2-y1). Now it'd have to be @-A@@-A+ if A is a built-in absolute value. Granted this only came up caues of my most recent post but I always figured that'd be a good way to expand golfscript: write down what functions would be handy to have, collect them, and add them as built-ins.
  • Convert an integer to a one-character string (equivalent of python's chr).
  • Spill a string onto the stack (currently {}/)
  • A version of : that consumes what is stored. This would have to not get 'stuck' to identifiers to be useful.
  • Operators for >=, <=
  • As someone suggested, a way to put a variable containing a block onto the stack without executing it. So you could reduce ifs of the form 1{\}{|}if to something like 1?\?|if
  • Built-in base64 conversion and zlib support to make embedding data take less characters
  • Beyond base64, make a custom base93 encoding (using all printable characters that aren't the string delimiter).
  • Shortcuts for 1$, 2$, 3$, 4$, 5$
  • An operator to copy the top two stack items as they are, i.e. \.@.@\

Claudiu

Posted 2013-12-31T18:58:15.527

Reputation: 3 870

-3

It'd be nice if the value written or computed in the last line of a function was automatically returned

xem

Posted 2013-12-31T18:58:15.527

Reputation: 5 523

That might be nice...in some other language. (No more annoying return statements at the end of functions! Yay! (But I haven't needed return statements ever, so...)) – CalculatorFeline – 2016-03-07T03:26:20.703

3It's stack-based, so... – marinus – 2013-12-31T19:30:31.087

1There's no such thing as a function. – Peter Taylor – 2013-12-31T19:31:39.430

Functions don't return anything... and they're called blocks – Doorknob – 2013-12-31T19:32:02.823