GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — assigning _ in the repl has side effects · Issue #5431 · nodejs/node

assigning _ in the repl has side effects #5431

New issue
Copy link
New issue
Copy link
Closed
Closed
assigning _ in the repl has side effects#5431
Copy link
Labels
replIssues and PRs related to the REPL subsystem.

Description

@calidion
calidion
opened on Feb 25, 2016
Issue body actions
  • Version: v4.2.3
  • Platform: Linux eric-ThinkPad-X220 3.19.0-51-generic Fix for path.resolve containing relative path to another drive in windows #57~14.04.1-Ubuntu SMP Fri Feb 19 14:36:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

In Nodejs REPL env, where var _ = require('lodash') failed to be assigned, but abc can.

> var _ = require('lodash');
undefined
> _
undefined
> var abc = require('lodash');
undefined
> abc
{ [Function: lodash]
  templateSettings: 
   { escape: /<%-([\s\S]+?)%>/g,
     evaluate: /<%([\s\S]+?)%>/g,
     interpolate: /<%=([\s\S]+?)%>/g,
     variable: '',
     imports: { _: [Circular] } },

Activity

  1. mscdex
    added
    replIssues and PRs related to the REPL subsystem.
    on Feb 25, 2016
  2. mscdex commented on Feb 25, 2016

    @mscdex
    mscdex
    on Feb 25, 2016
    Contributor
    More actions

    In the repl documentation it mentions that the _ variable is special and always refers to the result of the last expression. In other words, you cannot use _ in the repl for your own use, as it will get overwritten every time you execute a "line" of code.

  3. mscdex
    added
    invalidIssues and PRs that are invalid.
    on Feb 25, 2016
  4. calidion commented on Feb 25, 2016

    @calidion
    calidion
    on Feb 25, 2016
    Author
    More actions

    the use of _ is so common for lodash or underscore. I don't have any reason why _ is chosen to be the default result. . would be far more acceptable than _

  5. vkurchatkin commented on Feb 25, 2016

    @vkurchatkin
    vkurchatkin
    on Feb 25, 2016
    Contributor
    More actions

    . is not a valid identifier

    Reacted by Jonathan H, Lars Willighagen, Jacob and LuckyWindsck
  6. vkurchatkin
    closed this as completedon Feb 25, 2016
  7. rvagg commented on Feb 25, 2016

    @rvagg
    rvagg
    on Feb 25, 2016
    Member
    More actions

    Just out of interest I thought I've do some provenance work on this

    _ was introduced in repl.js back in the 25th of September 2009 @ 7674bd5

    Underscore was born almost exactly one month later, on the 26th of October 2009 @ jashkenas/underscore@02ede85

    Perhaps we should go argue to Underscore and lodash that they should change to something that won't conflict with Node?

    Reacted by Jacob
  8. vkurchatkin commented on Feb 25, 2016

    @vkurchatkin
    vkurchatkin
    on Feb 25, 2016
    Contributor
    More actions

    FWIW Chrome console uses $_ for this and it works the same way

    Reacted by Zeke Sikelianos and Linus Lee
  9. bnoordhuis commented on Feb 25, 2016

    @bnoordhuis
    bnoordhuis
    on Feb 25, 2016
    Member
    More actions

    To add to what @rvagg said, the underscore's behavior was copied from the python and ruby REPLs.

  10. calidion commented on Feb 25, 2016

    @calidion
    calidion
    on Feb 25, 2016
    Author
    More actions

    I think __ or __last or __xxx would be much acceptable where __ is known to be system reserved.

  11. bnoordhuis commented on Feb 25, 2016

    @bnoordhuis
    bnoordhuis
    on Feb 25, 2016
    Member
    More actions

    It's been _ for over half a decade now, it's not going to change.

    Reacted by Tyler Sheaffer
  12. vkurchatkin commented on Feb 25, 2016

    @vkurchatkin
    vkurchatkin
    on Feb 25, 2016
    Contributor
    More actions

    We could try two things:

    • warn on assignment to global _;
    • disable this behaviour when global _ is defined;
    Reacted by wmzy and Jacob
  13. calidion commented on Feb 25, 2016

    @calidion
    calidion
    on Feb 25, 2016
    Author
    More actions

    @vkurchatkin
    I would say that is a very good idea.
    💯

  14. rvagg commented on Feb 25, 2016

    @rvagg
    rvagg
    on Feb 25, 2016
    Member
    More actions

    I like that suggestion @vkurchatkin, would lead to fewer surprises like the one that prompted this issue

  15. silverwind commented on Feb 25, 2016

    @silverwind
    silverwind
    on Feb 25, 2016
    Contributor
    More actions

    Why not just disable _ functionality with a warning once it's being assigned to? Not being able to paste lodash examples in the REPL is not ideal, imho.

  16. silverwind
    reopened this on Feb 25, 2016
  17. silverwind
    removed
    invalidIssues and PRs that are invalid.
    on Feb 25, 2016
  18. Fishrock123
    changed the title [-]strange bug[/-] [+]assigning _ in the repl has side effects[/+] on Feb 25, 2016
  19. princejwesley commented on Feb 25, 2016

    @princejwesley
    princejwesley
    on Feb 25, 2016
    Contributor
    More actions

    I suggest to add an entry in help command like below

    node 🙈 ₹  node
    > .help
    break   Sometimes you get stuck, this gets you out
    clear   Alias for .break
    exit    Exit the repl
    help    Show repl options
    load    Load JS from a file into the REPL session
    save    Save all evaluated commands in this REPL session to a file
    _       Bound to last successfully evaluated expression
    >
    
    
  20. rvagg commented on Feb 26, 2016

    @rvagg
    rvagg
    on Feb 26, 2016
    Member
    More actions

    see #5438 for one option

  21. silverwind
    added a commit that references this issue on Mar 18, 2016

    repl: Assignment of _ allowed with warning

    ad8257f
  22. silverwind
    closed this as completedin ad8257fon Mar 18, 2016
  23. MylesBorins
    added
    lts-watch-v4.x
    on Apr 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.