Search Results

Search found 13794 results on 552 pages for 'variable scope'.

Page 3/552 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • uses for dynamic scope?

    - by Stephen
    Hi, I've been getting my hands wet with emacs lisp, and one thing that trips me up sometimes is the dynamic scope. Is there much of a future for it? Most languages I know use static scoping (or have moved to static scoping, like Python), and probably because I know it better I tend to prefer it. Are there specific applications/instances or examples where dynamic scope is more useful?

    Read the article

  • In languages which create a new scope each time in a loop block, a new local copy of the local loop

    - by Jian Lin
    It seems that in language like C, Java, and Ruby (as opposed to Javascript), a new scope is created for each iteration of a loop block, and the local variable defined for the loop is actually made into a local variable every single time and recorded in this new scope? For example, in Ruby: p RUBY_VERSION $foo = [] (1..5).each do |i| $foo[i] = lambda { p i } end (1..5).each do |j| $foo[j].call() end the print out is: [MacBook01:~] $ ruby scope.rb "1.8.6" 1 2 3 4 5 [MacBook01:~] $ So, it looks like when a new scope is created, a new local copy of i is also created and recorded in this new scope, so that when the function is executed at a later time, the "i" is found in those scope chains as 1, 2, 3, 4, 5 respectively. Is this true? (It sounds like a heavy operation). Contrast that with p RUBY_VERSION $foo = [] i = 0 (1..5).each do |i| $foo[i] = lambda { p i } end (1..5).each do |j| $foo[j].call() end This time, the i is defined before entering the loop, so Ruby 1.8.6 will not put this i in the new scope created for the loop block, and therefore when the i is looked up in the scope chain, it always refer to the i that was in the outside scope, and give 5 every time: [MacBook01:~] $ ruby scope2.rb "1.8.6" 5 5 5 5 5 [MacBook01:~] $ I heard that in Ruby 1.9, i will be treated as a local defined for the loop even when there is an i defined earlier? The operation of creating a new scope, creating a new local copy of i each time through the loop seems heavy, as it seems it wouldn't have matter if we are not invoking the functions at a later time. So when the functions don't need to be invoked at a later time, could the interpreter and the compiler to C / Java try to optimize it so that there is not local copy of i each time?

    Read the article

  • Rails nested models and data separation by scope

    - by jobrahms
    I have Teacher, Student, and Parent models that all belong to User. This is so that a Teacher can create Students and Parents that can or cannot log into the app depending on the teacher's preference. Student and Parent both accept nested attributes for User so a Student and User object can be created in the same form. All four models also belong to Studio so I can do data separation by scope. The current studio is set in application_controller.rb by looking up the current subdomain. In my students controller (all of my controllers, actually) I'm using @studio.students.new instead of Student.new, etc, to scope the new student to the correct studio, and therefore the correct subdomain. However, the nested User does not pick up the studio from its parent - it gets set to nil. I was thinking that I could do something like params[:student][:user_attributes][:studio_id] = @student.studio.id in the controller, but that would require doing attr_accessible :studio_id in User, which would be bad. How can I make sure that the nested User picks up the same scope that the Student model gets when it's created? student.rb class Student < ActiveRecord::Base belongs_to :studio belongs_to :user, :dependent => :destroy attr_accessible :user_attributes accepts_nested_attributes_for :user, :reject_if => :all_blank end students_controller.rb def create @student = @studio.students.new @student.attributes = params[:student] if @student.save redirect_to @student, :notice => "Successfully created student." else render :action => 'new' end end user.rb class User < ActiveRecord::Base belongs_to :studio accepts_nested_attributes_for :studio attr_accessible :email, :password, :password_confirmation, :remember_me, :studio_attributes devise :invitable, :database_authenticatable, :recoverable, :rememberable, :trackable end

    Read the article

  • Variable scope problem in JavaScript

    - by dfjhdfjhdf
    I declare a variable with the var word inside a function that handles Ajax requests, then later on in the function I have another function that should change the value of the variable but - my problem - it fails. How to settle the problem down? Here's similiar code I use: function sendRuest(someargums) { /* some code */ var the_variable; /* some code */ //here's that other function request.onreadystatechange = function() { if (request.readyState == 4) { switch (request.status) { case 200: //here the variable should be changed the_variable = request.responseXML; /* a lot of code */ //somewhere here the function closes } return the_variable; } var data = sendRequest(someargums); //and trying to read the data I get the undefined value

    Read the article

  • Android Static Variable Scope and Lifetime

    - by Edison
    I have an application that has a Service uses a ArrayList to store in the background for a very long time, the variable is initialized when the service started. The service is in the background and there will be frequent access to the variable (that's why i don't want to use file management or settings since it will be very expensive for a file I/O for the sake of battery life). The variable will likely to be ~1MB-2MB over its life tie. Is it safe to say that it will never be nulled by GC or the system or is there any way to prevent it? Thanks.

    Read the article

  • JS Anonymous Scope...

    - by Simon
    this Application.EventManager.on('Click', function(args) { // event listener, args is JSON TestAction.getContents(args.node.id, function(result, e) { console.log(result); this.add({ title: args.node.id, html: result }).show(); }); }); I'm really struggling with scope and anonymous functions... I want this (on the 1st line) to be the same object as this (on the 5th line)... .call() and .apply() seemed to be the right sort of idea but I don't want to trigger the event... just change it's scope.... For a bit of contexts... the this in question is a TabContainer and TestAction is a RPC that returns content... Thanks....

    Read the article

  • Scope of the Pages in a Silverlight application

    - by AngryHacker
    I have an app built with the Silverlight Navigation Application Template. I have a main form (e.g. MainPage.xaml) and a bunch of Silverlight Pages, which are swapped in and out of the main content area. In the MainPage.xaml, I have a DispatcherTimer which hits some Uri resources, regardless of which page I am on. Every now and then, it will inexplicably stop firing. I have an inkling that it has to do with the scope of various pages. Can pages inside the MainPage.xaml take away the scope from its parent? Or is this something much simpler?

    Read the article

  • validates_uniqueness_of...limiting scope - How do I restrict someone from creating a certain number

    - by bgadoci
    I have the following code: class Like < ActiveRecord::Base belongs_to :site validates_uniqueness_of :ip_address, :scope => [:site_id] end Which limits a person from "liking" a site more than one time based on a remote ip request. Essentially when someone "likes" a site, a record is created in the Likes table and I use a hidden field to request and pass their ip address to the :ip_address column in the like table. With the above code I am limiting the user to one "like" per their ip address. I would like to limit this to a certain number for instance 10. My initial thought was do something like this: validates_uniqueness_of :ip_address, :scope => [:site_id, :limit => 10] But that doesn't seem to work. Is there a simple syntax here that will allow me to do such a thing?

    Read the article

  • What did programmers do before variable scope, where everything is global?

    - by hydroparadise
    So, I am having to deal with seemingly archiac language (called PowerOn) where I have a main method, a few datatypes to define variables with, and has the ability to have sub-procedures (essentially void methods) that does not return a type nor accepts any arguements. The problem here is that EVERYTHING is global. I've read of these type of languages, but most books take the aproach "Ok, we use to use a horse and cariage, but now, here's a car so let's learn how to work on THAT!" We will NEVER relive those days". I have to admit, the mind is struggling to think outside of scope and extent. Well here I am. I am trying to figure out how to best manage nothing but global variables across several open methods. Yep, even iterators for for loops have to be defined globaly, which I find myself recycling in different parts of my code. My Question: for those that have this type experience, how did programmers deal with a large amount of variables in a global playing field? I have feeling it just became a mental juggling trick, but I would be interested to know if there were any known aproaches.

    Read the article

  • 'Object variable or With block variable not set' error when setting a range in VBA

    - by David Gard
    I have a function that creates a Pivot Table, but I am getting an error when I try to set a range that will be merged and have a title added to it. In the below code, pivot_title_range is a 'String' variable, and is optional when calling the funtion. title_range is a 'Range' variable. Both lines that set the range (whether or not the users declares pivot_title_range) cause the same error. If pivot_title_range = "" Then title_range = ActiveSheet.Range("B3:E4") Else title_range = ActiveSheet.Range(pivot_title_range) End If Here is the error that I am getting - Run-time error '91': Object variable or With block variable not set If required, here is a Pastebin of the full function - http://pastebin.com/L711jayc. The offending code starts on line 160. Is anybody able to tell me what I am doing wrong? Thanks.

    Read the article

  • Getting around IBActions limited scope

    - by Septih
    Hello, I have an NSCollectionView and the view is an NSBox with a label and an NSButton. I want a double click or a click of the NSButton to tell the controller to perform an action with the represented object of the NSCollectionViewItem. The Item View is has been subclassed, the code is as follows: #import <Cocoa/Cocoa.h> #import "WizardItem.h" @interface WizardItemView : NSBox { id delegate; IBOutlet NSCollectionViewItem * viewItem; WizardItem * wizardItem; } @property(readwrite,retain) WizardItem * wizardItem; @property(readwrite,retain) id delegate; -(IBAction)start:(id)sender; @end #import "WizardItemView.h" @implementation WizardItemView @synthesize wizardItem, delegate; -(void)awakeFromNib { [self bind:@"wizardItem" toObject:viewItem withKeyPath:@"representedObject" options:nil]; } -(void)mouseDown:(NSEvent *)event { [super mouseDown:event]; if([event clickCount] > 1) { [delegate performAction:[wizardItem action]]; } } -(IBAction)start:(id)sender { [delegate performAction:[wizardItem action]]; } @end The problem I've run into is that as an IBAction, the only things in the scope of -start are the things that have been bound in IB, so delegate and viewItem. This means that I cannot get at the represented object to send it to the delegate. Is there a way around this limited scope or a better way or getting hold of the represented object? Thanks.

    Read the article

  • jQuery variables and scope

    - by Peuge
    I am writing a jQuery plugin and am running into a few problems with regard to variables. For example I have the following skeleton structure for my plugin, which is going to act on a textbox. In my init function I want to set a variable and bind a keypress event to my textbox. That keypress event needs to call another function, in which I need the variable. Is this possible? (function($){ var methods = { init : function(options){ return this.each(function(){ var $this = $(this); var someVar = 'somevar'; $this.keypress(function(event){ //I want to call my customFunction }); }); }, customFunction : function(){ //I am wanting to access 'someVar' here }; $.fn.mynamespace = function(method){ //handle which method to call here }; })(jQuery); Many thanks in advance.

    Read the article

  • Basic Python: Exception raising and local variable scope / binding

    - by SuperJdynamite
    I have a basic "best practices" Python question. I see that there are already StackOverflow answers tangentially related to this question but they're mired in complicated examples or involve multiple factors. Given this code: #!/usr/bin/python def test_function(): try: a = str(5) raise b = str(6) except: print b test_function() what is the best way to avoid the inevitable "UnboundLocalError: local variable 'b' referenced before assignment" that I'm going to get in the exception handler? Does python have an elegant way to handle this? If not, what about an inelegant way? In a complicated function I'd prefer to avoid testing the existence of every local variable before I, for example, printed debug information about them.

    Read the article

  • Extending WikiPlex with Scope Augmenters

    - by mhawley
    [In addition to blogging, I am also using Twitter. Follow me: @matthawley] Another extension point with WikiPlex is Scope Augmenters. Scope Augmenters allow you to post process the collection of scopes to further augment, or insert/remove, new scopes prior to being rendered. WikiPlex comes with 3 out-of-the-box Scope Augmenters that it uses for indentation, tables, and lists. For reference, I'll be explaining… (read more)

    Read the article

  • Announcing the Drive Installation Scope

    Announcing the Drive Installation Scope On September 12, Google Drive released a new feature of great interest to many Drive web app developers: the installation scope. In this session we'll discuss the benefits of the installation scope, walk through the related documentation, and do a brief demo of how it works. From: GoogleDevelopers Views: 0 0 ratings Time: 00:00 More in Science & Technology

    Read the article

  • askubuntu scope seems to lag

    - by Nkciy84
    I installed the askubuntu scope/lens in Ubuntu 12.04 LTS but it seems to be almost extremely laggy. Sometimes when I enter text in the searchfield it takes a (whole lot of) while before something is displayed underneath the icons in text. Usualy I just see the first letters of the text I put in. Like: "damn, why is this scope so slow" i see "find 'dam'" on ask ubuntu" This 'bug' makes the lens/scope/thing almost impossible to use for me.

    Read the article

  • ORACLE PL/Scope

    - by Yaakov Davis
    I didn't find much data about the internals of PL/Scope. I'd like to use it to analyze identifiers in PL/SQL scripts. Does it work only on Oracle 11g instances? Can I reference its dlls to use it on a machine with only ORACLE 9/10 installed? In a related manner, do I have to execute the script in order to its identifiers to be analyzed?

    Read the article

  • JS: I'm not getting the scope

    - by Manuel
    Hi there, I'm trying to modify CouchDB's JS API to work asynchronous, but there is an error I cannot solve: Please find my JS API find at pastebin. If I call (new CouchDB("dbname")).designDocs() (line 193) I get an error because the okCallback function is not defined in the callback function. I don't know why; it should be defined in this scope.. Any hints are very welcome! Cheers, Manuel

    Read the article

  • Implementing dynamic scope when using CPS as intermediate language

    - by asandroq
    I am currently studying the implementation of programming languages and became interested in using Continuation-Passing Style as the intermediate language of the compiler. I also want to implement limited dynamic scope (for exception-handling or Scheme parameter objects) but I cannot find the relevant literature. I think it can be done with a separate environment passed as a variable to every closure, but this solution seems ugly to me. Could anyone point me to the relevant literature, or give me an idea of how this can be done?

    Read the article

  • #Define's scope throughout library?

    - by Mohit Deshpande
    Say I have a constant: #define PI 3.14 Say I have a static library with multiple header and source files. If I declare this in the header file, will its scope apply to all of the source files? Or do the source files need to include the header with the declaration of PI?

    Read the article

  • getJSON and variable scope in javascript

    - by nillls
    Hi! In order to make function calls to our back-end php code we've implemented something called an ActionProxy like this: function ActionProxy(action, input, callback){ $.post("ActionProxy.php?method="+action, { data: input}, function(data, textStatus, XMLHttpRequest){ //return data.ResponseWhatever } }); The problem we're having is that using data outside the ActionProxy is impossible due to variable scope limitations (we assume), setting var res = data.ResponseWhatever or return data.ResponseWhatever is pretty futile. How would one handle these responses most appropriately so that functions calling the actionproxy can access the response values?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >