Search Results

Search found 111 results on 5 pages for 'scoping'.

Page 1/5 | 1 2 3 4 5  | Next Page >

  • Building a common syntax and scoping framework.

    - by Ben DeMott
    Hello fellow programmers, I was discussing a project the other day with a colleague of mine and I was curious to see what others had to say or if such a thing already existed. Background There are many programming languages. There are many IDE's and source editors that highlight and edit source code. Following perfectly and exactly the rules of a language to present auto-complete options and understand scopes in the code is rather complex. This task is complex enough that most IDE's implement different source-editors as plugins that often re-implement the same features over and over but in a different way (netbeans). From what I can tell most IDE's and source editors re-implement parsers that use regular expressions, or some meta-syntax Naur Form to describe the languages grammer generically. These parsers are implemented over and over and over again. Question Has anyone attempted to unify or describe a set of features through an API and have a consistent interface to parsing various programming languages and dialects. I'm not describing an IDE - but a consistent API for any program to use to parse and obtain meta-information from the source code. I realize various programming languages offer many different features which are difficult to 'abstract' into a set of features, but I feel this would be a worthwhile venture. It seems to me that this could possibly allow the authors of interpreters to help maintain a central grammer intepreter for their language. the Python foundation could maintain the Python grammer api, ANSI the C grammer api, Oracle the Java grammer API, etc Example usage If this was API existed code documentation generators could theoretically work across all dialects and languages to some level. It wouldn't matter if your project used 5 different languages a single application could document all of them and the comments and doc-tags within. Has anyone attempted this comprehensively?

    Read the article

  • Variable scoping and the jQuery.getJSON() method

    - by jerome
    The jQuery.getJSON() method seems to ignore the normal rules of scoping within JavaScript. Given code such as this... someObject = { someMethod: function(){ var foo; $.getJSON('http://www.somewhere.com/some_resource', function(data){ foo = data.bar; }); alert(foo); // undefined } } someObject.someMethod(); Is there a best practice for accessing the value of the variable outside of the getJSON scope?

    Read the article

  • Scoping a home dev server

    - by AbhikRK
    Hi. I’m looking to build a multi-purpose home development server. In this post, I’m looking to outline what I want from such a system, and the ‘why’s of it, to some limited extent, and finally, some rudiments of how I’m looking to go about that. I’m mostly a developer, with just about some sysadmin familiarity. So, please excuse, correct me, and suggest on any ignorance which would come across in the following ;-) It will serve the following goals to start with:- NAS (Looking at using ZFS) Source control repo e.g Git server Database e.g MySQL server Continuous Integration e.g Hudson server Other stuff as and when they come up e.g RabbitMQ etc A development sandbox to play around with new stuff I want to achieve a high uptime for 2-5 as much as possible. They should run as independent services and with minimal maintenance. (e.g TurnKey Linux appliances) I’m thinking of running them as individual Xen DomUs. Then, maybe the NAS can be a Dom0 and 6 can be another DomU. The User for this would be mostly me. I can see 2-4 being sometimes used by 2-3 users, but that would be infrequent. I’m looking for a repeatable setup. Ideally I’d like to automate this setup through Chef or Puppet or something similar. Once everything runs, I want to be able to ssh/screen/tmux into 1-6 from my laptop or any other computer on the LAN/on-the-go. My queries are:- Is putting 1-6, all of them on a single box, a good idea? If so, what kind of hardware should I be looking at, for a low-cost, low-power setup? Although not at present, but in future I might be looking at adding audio/media servers to the mix. Would that impact the answers to 1? I have an old Pentium 3 and 810e motherboard combination. Is there any way I could put it to use? I had a look at the Sheevaplug, and was wondering if I could split off the NAS on its own using that. But ruled it out preliminarily due to its reported heating issues. Is it something i should still consider? Thanks in advance

    Read the article

  • Scoping a home dev server

    - by AbhikRK
    Hi. I’m looking to build a multi-purpose home development server. In this post, I’m looking to outline what I want from such a system, and the ‘why’s of it, to some limited extent, and finally, some rudiments of how I’m looking to go about that. I’m mostly a developer, with just about some sysadmin familiarity. So, please excuse, correct me, and suggest on any ignorance which would come across in the following ;-) It will serve the following goals to start with:- NAS (Looking at using ZFS) Source control repo e.g Git server Database e.g MySQL server Continuous Integration e.g Hudson server Other stuff as and when they come up e.g RabbitMQ etc A development sandbox to play around with new stuff I want to achieve a high uptime for 2-5 as much as possible. They should run as independent services and with minimal maintenance. (e.g TurnKey Linux appliances) I’m thinking of running them as individual Xen DomUs. Then, maybe the NAS can be a Dom0 and 6 can be another DomU. The User for this would be mostly me. I can see 2-4 being sometimes used by 2-3 users, but that would be infrequent. I’m looking for a repeatable setup. Ideally I’d like to automate this setup through Chef or Puppet or something similar. Once everything runs, I want to be able to ssh/screen/tmux into 1-6 from my laptop or any other computer on the LAN/on-the-go. My queries are:- Is putting 1-6, all of them on a single box, a good idea? If so, what kind of hardware should I be looking at, for a low-cost, low-power setup? Although not at present, but in future I might be looking at adding audio/media servers to the mix. Would that impact the answers to 1? I have an old Pentium 3 and 810e motherboard combination. Is there any way I could put it to use? I had a look at the Sheevaplug, and was wondering if I could split off the NAS on its own using that. But ruled it out preliminarily due to its reported heating issues. Is it something i should still consider? Thanks in advance Have posted this question previously on SuperUser but no responses yet. So was wondering if this is a more apt forum for this.

    Read the article

  • Need Help Scoping a Server to use for study (MCITP Ent Admin + SharePoint 2010)

    - by AVFamily76
    i need to study for mcitp, but i also need to study for sharepoint 2010 i have a poweredge 1850 with two single-core CPUs + two 73G drives - it kills me on electricity, so don't want to use it, and it won't do VT, but it could be one of three boxes for a lab that's cheap, but will cost a lot on electricity i was thinking . . . OPTION #1 Opteron 4170 HE (50 watt chip), 6-core, only two-bills ($200), but the board's are $250, so that's an $800 box, then get another box to dual-boot Win7/Hyper-V on the cheap...? OPTION #2 Used Quad - but how many VM's that are really banging away could it run at same time? (Server 2008r2, SQL 2008r2, Search Server) OPTION #3 Study from books and just get one box that can run two VM's at same time, even if slowly. the last time i had and used a home lab was five years ago when i had a DC, SQL, Exchange and business app box, that's where i got my server skills was just banging on it for four years, but didn't read any books, so now i have to get certified and know the material, and just am not sure how much attention i should pay to the box i use versus the studying time and reading. sorry it's a subjective question, and am obviously open to all sorts of abuse here, but hope you can tell me also how many VM's i can run at the same time given what they'll be doing (SQL and SharePoint FAST search server are resource hungry) thanks!

    Read the article

  • MySql scoping problem with correlated subqueries

    - by Rolf
    Hi, I'm having this Mysql query, It works: SELECT nom ,prenom ,(SELECT GROUP_CONCAT(category_en) FROM (SELECT DISTINCT category_en FROM categories c WHERE id IN (SELECT DISTINCT category_id FROM m3allems_to_categories m2c WHERE m3allem_id = 37) ) cS ) categories ,(SELECT GROUP_CONCAT(area_en) FROM (SELECT DISTINCT area_en FROM areas c WHERE id IN (SELECT DISTINCT area_id FROM m3allems_to_areas m2a WHERE m3allem_id = 37) ) aSq ) areas FROM m3allems m WHERE m.id = 37 The result is: nom prenom categories areas Man Multi Carpentry,Paint,Walls Beirut,Baalbak,Saida It works correclty, but only when i hardcode into the query the id that I want (37). I want it to work for all entries in the m3allem table, so I try this: SELECT nom ,prenom ,(SELECT GROUP_CONCAT(category_en) FROM (SELECT DISTINCT category_en FROM categories c WHERE id IN (SELECT DISTINCT category_id FROM m3allems_to_categories m2c WHERE m3allem_id = m.id) ) cS ) categories ,(SELECT GROUP_CONCAT(area_en) FROM (SELECT DISTINCT area_en FROM areas c WHERE id IN (SELECT DISTINCT area_id FROM m3allems_to_areas m2a WHERE m3allem_id = m.id) ) aSq ) areas FROM m3allems m And I get an error: Unknown column 'm.id' in 'where clause' Why? From the MySql manual: 13.2.8.7. Correlated Subqueries [...] Scoping rule: MySQL evaluates from inside to outside. So... do this not work when the subquery is in a SELECT section? I did not read anything about that. Does anyone know? What should I do? It took me a long time to build this query... I know it's a monster query but it gets what I want in a single query, and I am so close to getting it to work! Can anyone help?

    Read the article

  • C++ arrays as parameters, EDIT: now includes variable scoping

    - by awshepard
    Alright, I'm guessing this is an easy question, so I'll take the knocks, but I'm not finding what I need on google or SO. I'd like to create an array in one place, and populate it inside a different function. I define a function: void someFunction(double results[]) { for (int i = 0; i<100; ++i) { for (int n = 0; n<16; ++n) //note this iteration limit { results[n] += i * n; } } } That's an approximation to what my code is doing, but regardless, shouldn't be running into any overflow or out of bounds issues or anything. I generate an array: double result[16]; for(int i = 0; i<16; i++) { result[i] = -1; } then I want to pass it to someFunction someFunction(result); When I set breakpoints and step through the code, upon entering someFunction, results is set to the same address as result, and the value there is -1.000000 as expected. However, when I start iterating through the loop, results[n] doesn't seem to resolve to *(results+n) or *(results+n*sizeof(double)), it just seems to resolve to *(results). What I end up with is that instead of populating my result array, I just get one value. What am I doing wrong? EDIT Oh fun, I have a typo: it wasn't void someFunction(double results[]). It was: void someFunction(double result[])... So perhaps this is turning into a scoping question. If my double result[16] array is defined in a main.cpp, and someFunction is defined in a Utils.h file that's included by the main.cpp, does the result variable in someFunction then wreak havoc on the result array in main?

    Read the article

  • Dynamic scoping in Clojure?

    - by j-g-faustus
    Hi, I'm looking for an idiomatic way to get dynamically scoped variables in Clojure (or a similar effect) for use in templates and such. Here is an example problem using a lookup table to translate tag attributes from some non-HTML format to HTML, where the table needs access to a set of variables supplied from elsewhere: (def *attr-table* ; Key: [attr-key tag-name] or [boolean-function] ; Value: [attr-key attr-value] (empty array to ignore) ; Context: Variables "tagname", "akey", "aval" '( ; translate :LINK attribute in <a> to :href [:LINK "a"] [:href aval] ; translate :LINK attribute in <img> to :src [:LINK "img"] [:src aval] ; throw exception if :LINK attribute in any other tag [:LINK] (throw (RuntimeException. (str "No match for " tagname))) ; ... more rules ; ignore string keys, used for internal bookkeeping [(string? akey)] [] )) ; ignore I want to be able to evaluate the rules (left hand side) as well as the result (right hand side), and need some way to put the variables in scope at the location where the table is evaluated. I also want to keep the lookup and evaluation logic independent of any particular table or set of variables. I suppose there are similar issues involved in templates (for example for dynamic HTML), where you don't want to rewrite the template processing logic every time someone puts a new variable in a template. Here is one approach using global variables and bindings. I have included some logic for the table lookup: ;; Generic code, works with any table on the same format. (defn rule-match? [rule-val test-val] "true if a single rule matches a single argument value" (cond (not (coll? rule-val)) (= rule-val test-val) ; plain value (list? rule-val) (eval rule-val) ; function call :else false )) (defn rule-lookup [test-val rule-table] "looks up rule match for test-val. Returns result or nil." (loop [rules (partition 2 rule-table)] (when-not (empty? rules) (let [[select result] (first rules)] (if (every? #(boolean %) (map rule-match? select test-val)) (eval result) ; evaluate and return result (recur (rest rules)) ))))) ;; Code specific to *attr-table* (def tagname) ; need these globals for the binding in html-attr (def akey) (def aval) (defn html-attr [tagname h-attr] "converts to html attributes" (apply hash-map (flatten (map (fn [[k v :as kv]] (binding [tagname tagname akey k aval v] (or (rule-lookup [k tagname] *attr-table*) kv))) h-attr )))) (defn test-attr [] "test conversion" (prn "a" (html-attr "a" {:LINK "www.google.com" "internal" 42 :title "A link" })) (prn "img" (html-attr "img" {:LINK "logo.png" }))) user=> (test-attr) "a" {:href "www.google.com", :title "A link"} "img" {:src "logo.png"} This is nice in that the lookup logic is independent of the table, so it can be reused with other tables and different variables. (Plus of course that the general table approach is about a quarter of the size of the code I had when I did the translations "by hand" in a giant cond.) It is not so nice in that I need to declare every variable as a global for the binding to work. Here is another approach using a "semi-macro", a function with a syntax-quoted return value, that doesn't need globals: (defn attr-table [tagname akey aval] `( [:LINK "a"] [:href ~aval] [:LINK "img"] [:src ~aval] [:LINK] (throw (RuntimeException. (str "No match for " tagname))) ; ... more rules [(string? ~akey)] [] ))) Only a couple of changes are needed to the rest of the code: In rule-match?, when syntax-quoted the function call is no longer a list: - (list? rule-val) (eval rule-val) + (seq? rule-val) (eval rule-val) In html-attr: - (binding [tagname tagname akey k aval v] - (or (rule-lookup [k tagname] *attr-table*) kv))) + (or (rule-lookup [k tagname] (attr-table tagname k v)) kv))) And we get the same result without globals. (And without dynamic scoping.) Are there other alternatives to pass along sets of variable bindings declared elsewhere, without the globals required by Clojure's binding? Is there an idiomatic way of doing it, like Ruby's binding or Javascript's function.apply(context)?

    Read the article

  • Scope of Derived Tables in SQL Server

    - by FailBoy
    I've been looking into SQL recently and exploring a bit. in regards to Temp Tables I have discovered 3 different temp table types: 1) CREATE TABLE #TempTable 2) DECLARE TABLE @TempTable 3) SELECT * FROM (SELECT * FROM Customers) AS TempTable Now I understand the scope behind the #TempTable and the @TempTable types, but what about the derived table as in example 3? Where does this derived table get stored? and if it is declared in 1 transaction, can a 2nd transaction access it, or is the scoping of Derived Tables that same as example 1 and 2?

    Read the article

  • perl, module variable

    - by Mike
    I don't really understand how scoping works in perl modules. This doesn't print anything. I would like it if running a.pl printed 1 b.pm $f=1; a.pl use b; print $f

    Read the article

  • C++ scoping error

    - by Pat Murray
    I have the following code: #include "Student.h" #include "SortedList.h" using namespace std; int main() { // points to the sorted list object SortedList *list = new SortedList; //This is line 17 // array to hold 100 student objects Student create[100]; int num = 100000; // holds different ID numbers // fills an array with 100 students of various ID numbers for (Student &x : create) { x = new Student(num); num += 100; } // insert all students into the sorted list for (Student &x : create) list->insert(&x); delete list; return 0; } And I keep getting the compile time error: main.cpp: In function ‘int main()’: main.cpp:17: error: ‘SortedList’ was not declared in this scope main.cpp:17: error: ‘list’ was not declared in this scope main.cpp:17: error: expected type-specifier before ‘SortedList’ main.cpp:17: error: expected `;' before ‘SortedList’ main.cpp:20: error: ‘Student’ was not declared in this scope main.cpp:20: error: expected primary-expression before ‘]’ token main.cpp:20: error: expected `;' before ‘create’ main.cpp:25: error: expected `;' before ‘x’ main.cpp:31: error: expected primary-expression before ‘for’ main.cpp:31: error: expected `;' before ‘for’ main.cpp:31: error: expected primary-expression before ‘for’ main.cpp:31: error: expected `)' before ‘for’ main.cpp:31: error: expected `;' before ‘x’ main.cpp:34: error: type ‘<type error>’ argument given to ‘delete’, expected pointer main.cpp:35: error: expected primary-expression before ‘return’ main.cpp:35: error: expected `)' before ‘return’ My Student.cpp and SortedList.cpp files compile just fine. They both also include .h files. I just do not understand why I get an error on that line. It seems to be a small issue though. Any insight would be appreciated. UPDATE1: I originally had .h files included, but i changed it when trying to figure out the cause of the error. The error remains with the .h files included though. UPDATE2: SortedList.h #ifndef SORTEDLIST_H #define SORTEDLIST_H #include "Student.h" /* * SortedList class * * A SortedList is an ordered collection of Students. The Students are ordered * from lowest numbered student ID to highest numbered student ID. */ class SortedList { public: SortedList(); // Constructs an empty list. SortedList(const SortedList & l); // Constructs a copy of the given student object ~SortedList(); // Destructs the sorted list object const SortedList & operator=(const SortedList & l); // Defines the assignment operator between two sorted list objects bool insert(Student *s); // If a student with the same ID is not already in the list, inserts // the given student into the list in the appropriate place and returns // true. If there is already a student in the list with the same ID // then the list is not changed and false is returned. Student *find(int studentID); // Searches the list for a student with the given student ID. If the // student is found, it is returned; if it is not found, NULL is returned. Student *remove(int studentID); // Searches the list for a student with the given student ID. If the // student is found, the student is removed from the list and returned; // if no student is found with the given ID, NULL is returned. // Note that the Student is NOT deleted - it is returned - however, // the removed list node should be deleted. void print() const; // Prints out the list of students to standard output. The students are // printed in order of student ID (from smallest to largest), one per line private: // Since Listnodes will only be used within the SortedList class, // we make it private. struct Listnode { Student *student; Listnode *next; }; Listnode *head; // pointer to first node in the list static void freeList(Listnode *L); // Traverses throught the linked list and deallocates each node static Listnode *copyList(Listnode *L); // Returns a pointer to the first node within a particular list }; #endif #ifndef STUDENT_H #define STUDENT_H Student.h #ifndef STUDENT_H #define STUDENT_H /* * Student class * * A Student object contains a student ID, the number of credits, and an * overall GPA. */ class Student { public: Student(); // Constructs a default student with an ID of 0, 0 credits, and 0.0 GPA. Student(int ID); // Constructs a student with the given ID, 0 credits, and 0.0 GPA. Student(int ID, int cr, double grPtAv); // Constructs a student with the given ID, number of credits, and GPA.\ Student(const Student & s); // Constructs a copy of another student object ~Student(); // Destructs a student object const Student & operator=(const Student & rhs); // Defines the assignment operator between two student objects // Accessors int getID() const; // returns the student ID int getCredits() const; // returns the number of credits double getGPA() const; // returns the GPA // Other methods void update(char grade, int cr); // Updates the total credits and overall GPA to take into account the // additions of the given letter grade in a course with the given number // of credits. The update is done by first converting the letter grade // into a numeric value (A = 4.0, B = 3.0, etc.). The new GPA is // calculated using the formula: // // (oldGPA * old_total_credits) + (numeric_grade * cr) // newGPA = --------------------------------------------------- // old_total_credits + cr // // Finally, the total credits is updated (to old_total_credits + cr) void print() const; // Prints out the student to standard output in the format: // ID,credits,GPA // Note: the end-of-line is NOT printed after the student information private: int studentID; int credits; double GPA; }; #endif

    Read the article

  • Lexical and dynamic scoping in Mathematica: Local variables with Module, With, and Block

    - by dreeves
    The following code returns 14 as you'd expect: Block[{expr}, expr = 2 z; f[z_] = expr; f[7]] But if you change that Block to a Module then it returns 2*z. It seems to not matter what other variables besides expr you localize. I thought I understood Module, Block, and With in Mathematica but I can't explain the difference in behavior between Module and Block in this example. Related resources: Tutorial on Modularity and the Naming of Things from the Mathematica documentation Excerpt from a book by Paul R. Wellin, Richard J. Gaylord, and Samuel N. Kamin Explanation from Dave Withoff on the Mathematica newsgroup

    Read the article

  • Problem with Variable Scoping in Rebol's Object

    - by Rebol Tutorial
    I have modified the rebodex app so that it can be called from rebol's console any time by typing rebodex. To show the title of the app, I need to store it in app-title: system/script/header/title so tha it could be used later in view/new/title dex reform [self/app-title version] That works but as you can see I have named the var name "app-title", but if I use "title" instead, the window caption would show weird stuff (vid code). Why ? REBOL [ Title: "Rebodex" Date: 23-May-2010 Version: 2.1.1 File: %rebodex.r Author: "Carl Sassenrath" Modification: "Rebtut" Purpose: "A simple but useful address book contact database." Email: %carl--rebol--com library: [ level: 'intermediate platform: none type: 'tool domain: [file-handling DB GUI] tested-under: none support: none license: none see-also: none ] ] rebodex.context: context [ app-title: system/script/header/title version: system/script/header/version set 'rebodex func[][ names-path: %names.r ;data file name-list: none fields: [name company title work cell home car fax web email smail notes updat] names: either exists? names-path [load names-path][ [[name "Carl Sassenrath" title "Founder" company "REBOL Technologies" email "%carl--rebol--com" web "http://www.rebol.com"]] ] brws: [ if not empty? web/text [ if not find web/text "http://" [insert web/text "http://"] error? try [browse web/text] ] ] dial: [request [rejoin ["Dial number for " name/text "? (Not implemented.)"] "Dial" "Cancel"]] dex-styles: stylize [ lab: label 60x20 right bold middle font-size 11 btn: button 64x20 font-size 11 edge [size: 1x1] fld: field 200x20 font-size 11 middle edge [size: 1x1] inf: info font-size 11 middle edge [size: 1x1] ari: field wrap font-size 11 edge [size: 1x1] with [flags: [field tabbed]] ] dex-pane1: layout/offset [ origin 0 space 2x0 across styles dex-styles lab "Name" name: fld bold return lab "Title" title: fld return lab "Company" company: fld return lab "Email" email: fld return lab "Web" brws web: fld return lab "Address" smail: ari 200x72 return lab "Updated" updat: inf 200x20 return ] 0x0 updat/flags: none dex-pane2: layout/offset [ origin 0 space 2x0 across styles dex-styles lab "Work #" dial work: fld 140 return lab "Home #" dial home: fld 140 return lab "Cell #" dial cell: fld 140 return lab "Alt #" dial car: fld 140 return lab "Fax #" fax: fld 140 return lab "Notes" notes: ari 140x72 return pad 136x1 btn "Close" #"^q" [store-entry save-file unview] ] 0x0 dex: layout [ origin 8x8 space 0x1 styles dex-styles srch: fld 196x20 bold across rslt: list 180x150 [ nt: txt 178x15 middle font-size 11 [ store-entry curr: cnt find-name nt/text update-entry unfocus show dex ] ] supply [ cnt: count + scroll-off face/text: "" face/color: snow if not n: pick name-list cnt [exit] face/text: select n 'name face/font/color: black if curr = cnt [face/color: system/view/vid/vid-colors/field-select] ] sl: slider 16x150 [scroll-list] return return btn "New" #"^n" [new-name] btn "Del" #"^d" [delete-name unfocus update-entry search-all show dex] btn "Sort" [sort names sort name-list show rslt] return at srch/offset + (srch/size * 1x0) bx1: box dex-pane1/size bx2: box dex-pane2/size return ] bx1/pane: dex-pane1/pane bx2/pane: dex-pane2/pane rslt/data: [] this-name: first names name-list: copy names curr: none search-text: "" scroll-off: 0 srch/feel: make srch/feel [ redraw: func [face act pos][ face/color: pick face/colors face system/view/focal-face if all [face = system/view/focal-face face/text search-text] [ search-text: copy face/text search-all if 1 = length? name-list [this-name: first name-list update-entry show dex] ] ] ] update-file: func [data] [ set [path file] split-path names-path if not exists? path [make-dir/deep path] write names-path data ] save-file: has [buf] [ buf: reform [{REBOL [Title: "Name Database" Date:} now "]^/[^/"] foreach n names [repend buf [mold n newline]] update-file append buf "]" ] delete-name: does [ remove find/only names this-name if empty? names [append-empty] save-file new-name ] clean-names: function [][n][ forall names [ if any [empty? first names none? n: select first names 'name empty? n][ remove names ] ] names: head names ] search-all: function [] [ent flds] [ clean-names clear name-list flds: [name] either empty? search-text [insert name-list names][ foreach nam names [ foreach word flds [ if all [ent: select nam word find ent search-text][ append/only name-list nam break ] ] ] ] scroll-off: 0 sl/data: 0 resize-drag scroll-list curr: none show [rslt sl] ] new-name: does [ store-entry clear-entry search-all append-empty focus name ; update-entry ] append-empty: does [append/only names this-name: copy []] find-name: function [str][] [ foreach nam names [ if str = select nam 'name [ this-name: nam break ] ] ] store-entry: has [val ent flag] [ flag: 0 if not empty? trim name/text [ foreach word fields [ val: trim get in get word 'text either ent: select this-name word [ if ent val [insert clear ent val flag: flag + 1] ][ if not empty? val [repend this-name [word copy val] flag: flag + 1] ] if flag = 1 [flag: 2 updat/text: form now] ] if not zero? flag [save-file] ] ] update-entry: does [ foreach word fields [ insert clear get in get word 'text any [select this-name word ""] ] show rslt ] clear-entry: does [ clear-fields bx1 clear-fields bx2 updat/text: form now unfocus show dex ] show-names: does [ clear rslt/data foreach n name-list [ if n/name [append rslt/data n/name] ] show rslt ] scroll-list: does [ scroll-off: max 0 to-integer 1 + (length? name-list) - (100 / 16) * sl/data show rslt ] do resize-drag: does [sl/redrag 100 / max 1 (16 * length? name-list)] center-face dex new-name focus srch show-names view/new/title dex reform [app-title version] insert-event-func [ either all [event/type = 'close event/face = dex][ store-entry unview ][event] ] do-events ] ]

    Read the article

  • Scoping inside Javascript anonymous functions

    - by DCD
    I am trying to make a function return data from an ajax call that I can then use. The issue is the function itself is called by many objects, e.g.: function ajax_submit (obj) { var id = $(obj).attr('id'); var message = escape ($("#"+id+" .s_post").val ()); var submit_string = "action=post_message&message="+message; $.ajax({ type: "POST", url: document.location, data: submit_string, success: function(html, obj) { alert (html); } }); return false; } Which means that inside the anonymous 'success' function I have no way of knowing what the calling obj (or id) actually are. The only way I can think of doing it is to attach id to document but that just seems a bit too crude. Is there another way of doing this?

    Read the article

  • scoping problem in recursive closure

    - by wiso
    why this work: def function1(): a = 10 def function2(): print a function2() but this not: def function1(): a = 10 def function2(): print a a -= 1 if a>0: function2() function2() error: UnboundLocalError: local variable 'a' referenced before assignment

    Read the article

  • Dependency injection: Scoping by region (Guice, Spring, Whatever)

    - by Itay
    Here's a simplified version of my needs. I have a program where every B object has its own C and D object, injected through Guice. In addition an A object is injected into every C and D objects. What I want: that for each B object, its C and D objects will be injected with the same A object. Specifically, I want the output of the program (below) to be: Created C0 with [A0] Created D0 with [A0] Created B0 with [C0, D0] Created C1 with [A1] Created D1 with [A1] Created B1 with [C1, D1] Where it currently produces the following output: Created C0 with [A0] Created D0 with [A1] <-- Should be A0 Created B0 with [C0, D0] Created C1 with [A2] <-- Should be A1 Created D1 with [A3] <-- Should be A1 Created B1 with [C1, D1] I am expecting DI containers to allow this kind of customization but so far I had no luck in finding a solution. Below is my Guice-based code, but a Spring-based (or other DI containers-based) solution is welcome. import java.util.Arrays; import com.google.inject.*; public class Main { public static class Super { private static Map<Class<?>,Integer> map = new HashMap<Class<?>,Integer>(); private Integer value; public Super(Object... args) { value = map.get(getClass()); value = value == null ? 0 : ++value; map.put(getClass(), value); if(args.length > 0) System.out.println("Created " + this + " with " + Arrays.toString(args)); } @Override public final String toString() { return "" + getClass().getSimpleName().charAt(0) + value; } } public interface A { } public static class AImpl extends Super implements A { } public interface B { } public static class BImpl extends Super implements B { @Inject public BImpl(C c, D d) { super(c,d); } } public interface C { } public static class CImpl extends Super implements C { @Inject public CImpl(A a) { super(a); } } public interface D { } public static class DImpl extends Super implements D { @Inject public DImpl(A a) { super(a); } } public static class MyModule extends AbstractModule { @Override protected void configure() { bind(A.class).to(AImpl.class); bind(B.class).to(BImpl.class); bind(C.class).to(CImpl.class); bind(D.class).to(DImpl.class); } } public static void main(String[] args) { Injector inj = Guice.createInjector(new MyModule()); inj.getInstance(B.class); inj.getInstance(B.class); } }

    Read the article

  • javascript scoping in for loop

    - by user121196
    consider the following javascript code, console.log always prints "focus 1" where 2 is the input length. how should I rewrite the code to prints the looping variable i correctly for (var i = 0; i < inputs.length; i++) { var curIndex = i; inputs[i].addListener('focus', function(thisfield, evt){ console.log('focus '+curIndex); }); }

    Read the article

  • Rails HABTM Scoping to current subdomain

    - by Rabbott
    I have the following associations: class User < ActiveRecord::Base has_and_belongs_to_many :brands, :join_table => 'brands_users' has_and_belongs_to_many :companies, :join_table => 'companies_users' end class Brand < ActiveRecord::Base belongs_to :company has_and_belongs_to_many :users, :join_table => 'brands_users' end class Company < ActiveRecord::Base has_and_belongs_to_many :users, :join_table => 'companies_users' has_many :brands, :order => :name end While editing a user I am using the checkbox list of brands. So that I can assign users 'access' to brands, the brands that show up are only the brands that belong to the current company (defined by the subdomain [using subdomain_fu]). The problem I am running into is that when using the default HABTM functionality and the checkbox list, upon save, Rails removes ALL user-brand associations, then re-adds just the ones for the form I just submitted.. How do I scope that to only remove associations of brands who belong to the current company, defined in the subdomain?

    Read the article

  • 'Lexical' scoping of type parameters in C#

    - by leppie
    I have 2 scenarios. This fails: class F<X> { public X X { get; set; } } error CS0102: The type 'F' already contains a definition for 'X' This works: class F<X> { class G { public X X { get; set; } } } The only logical explanation is that in the second snippet the type parameter X is out of scope, which is not true... Why should a type parameter affect my definitions in a type? IMO, for consistency, either both should work or neither should work. Any other ideas? PS: I call it 'lexical', but it probably is not not the correct term.

    Read the article

  • Scoping Issue with PHP Arrays

    - by Nik
    I'm trying to solve this problem where I have a unique array of values within a specific range. Take this scenario: Generate a fixed value array (90) with unique entries. If you find a duplicate, remove, reindex, and fill the void. I'm running into the problem that conditional statements do not allow you to interact with an array outside of it's scope. I'm aware of array_unique but it doesn't refill those gaps, just makes them. How do I refill those gaps?

    Read the article

  • Scoping in embedded groovy scripts

    - by Aaron Digulla
    In my app, I use Groovy as a scripting language. To make things easier for my customers, I have a global scope where I define helper classes and constants. Currently, I need to run the script (which builds the global scope) every time a user script is executed: context = setupGroovy(); runScript( context, "global.groovy" ); // Can I avoid doing this step every time? runScript( context, "user.groovy" ); Is there a way to setup this global scope once and just tell the embedded script interpreter: "Look here if you can't find a variable"? That way, I could run the global script once. Note: Security is not an issue here but if you know a way to make sure the user can't modify the global scope, that's an additional plus.

    Read the article

  • Scoping two models on approved

    - by Shaun Frost Duke Jackson
    I have three models (Book,Snippet,User) and I'd like to create a scope for where(:approved = true) I'm doing this so I can use the merit gem to define ranking based on count of approved. I'm thinking that writing this as a scope might be to complex but I don't know as I've just started leaning scopes. I've currently got this in my Book & Snippet Model: scope :approved, -> { where(approved: true) } I've playing around with this in my user model but I don't think it's correct: scope :approved, joins(:books && :snippets) Could anyone help start me off or give me some suggestions on what to read?

    Read the article

  • C++ Scoping and ambiguity in constructor overloads

    - by loarabia
    I've tried the following code snippet in 3 different compilers (G++, clang++, CL.exe) and they all report to me that they cannot disambiguate the overloaded constructors. Now, I know how I could modify the call to the constructor to make it pick one or the other (either make explicit that the second argument is a unsigned literal value or explicitly cast it). However, I'm curious why the compiler would be attempting to choose between constructors in the first place given that one of the constructors is private and the call to the constructor is happening in the main function which should be outside the class's scope. Can anyone enlighten me? class Test { private: Test(unsigned int a, unsigned int *b) { } public: Test(unsigned int a, unsigned int b) { } }; int main() { Test t1 = Test(1,0); // compiler is confused }

    Read the article

1 2 3 4 5  | Next Page >