Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7071123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:38:59+00:00 2026-05-28T05:38:59+00:00

Small query related scope of the procedure proc lappend {args} { set a $args

  • 0

Small query related scope of the procedure

proc lappend {args} {
   set a $args
   lappend a testing ;# want to call the inbuilt tcl lappend command
   puts "$a"
}

set list {new to tcl}
lappend $list
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:38:59+00:00Added an answer on May 28, 2026 at 5:38 am

    If you just do that, it won’t work. It’ll replace the standard lappend and you’ll get an infinite recursion (well, you’ll hit a stack-depth check). There are several ways to get around this.

    Putting your code in a namespace

    If your code is in a namespace, it will resolve the lappend within that namespace first and only use the global namespace if that local search fails. You can use this like this:

    namespace eval myNS {
        proc lappend {args} {
            set a $args
            ::lappend a testing ;# Force the use of the global lappend command
            puts "$a"
        }
    
        set list {new to tcl}
        lappend $list
    }
    

    There are variations on that possible, namespace eval myNS {source example.tcl} (with your code being almost verbatim in that sourced file) being one if the more interesting ones as it allows the code to be mostly agnostic to the namespace.

    Renaming the global lappend command

    You can also move the standard command out of the way like this:

    rename lappend lappend_original
    proc lappend {args} {
       set a $args
       lappend_original a testing
       puts "$a"
    }
    
    set list {new to tcl}
    lappend $list
    

    This technique works just fine, so long as you don’t have too much code warring over who has the actual original command. It’s been used by many Tcl scripts over the years.

    Real problem’s solution: execution tracing

    Of course, the lappend command isn’t one that you really want to replace as it is heavily used in much Tcl library code. For the problem of figuring out where a piece of code is actually calling lappend and what arguments are being passed in, it’s far better to be using an execution trace. (The link there is to the Tcl 8.6 documentation, but this API has been in place since Tcl 8.4 so you should have it available.)

    proc runningLappend {cmdAndArgs operation} {
        puts [lrange $cmdAndArgs 1 end]
    }
    trace add execution lappend enter runningLappend
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small site where I want to get Related Videos on basis
I have a small query related to OOP concept in C#. I have an
I have this small SQL query. SELECT a.`id` , a.`title` , a.`date` , (
I have a small but significant query. I'll give a similiar use case but
I'm creating a small forum. Attempting to run SElECT... JOIN... query too pick up
I need some help adding conditions to a linq query. Take this small example
Hi I need small query here are my tables user table userid username user001
I written a small query and in Linqpad its working well but (see below)
I have a small query.I just started out with the SWT programming and learnt
I'm trying to scrape using Google I'm Feeling Lucky button. For small query like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.