From: Xiong Chiamiov Date: 2008-09-12T17:15:42+09:00 Subject: Re: pass by reference in each loop Robert Klemme wrote: > 2008/9/12 Xiong Chiamiov : >>> That's quite near to what I suggested: just drop all the @a, @b etc. and >>> stuff everything in an array - or have multiple arrays, one per class of >>> data (i.e. data which undergoes wml and data which does not). Anyway, >>> chances are that you'll be able to find an elegant solution without >>> needing to change the language. >> >> I don't think I understood what you were suggesting the first time. If >> I understand what you're suggesting, it is to have the values themselves >> in the array, rather than variables pointing *to* those values, yes? > > What exactly do you mean by "variable pointing to those values"? Well, I'm not quite sure how to explain it. I think you cleared up what I was thinking right after this part, though: Robert Klemme wrote: > The value > (object) does not care how many references are around pointing to it. > With > > @x = Object.new > @y = Object.new > @a = [@x, @y] > > and > > @a = [Object.new, Object.new] > > there is no difference with regard to array contents. > Yep. Problem is, you present just a very tiny piece of your > application so it is extremely hard for use to suggest an appropriate > solution. Ah, I knew I had part of it online somewhere: http://production.xyztextbooks.com/wml.php/generator . This is the PHP version (before I converted it to Rails), so it hasn't had the benefit of some bugfixes and such, but you can at least *see* what I'm talking about. This page (http://production.xyztextbooks.com/wml.php/generator/syntax) has some of the basic syntactical things for this. Essentially, there is an application called Webwork that uses a special dialect of Perl intermingled with Tex, and I'm created a front-end to problem-creation, which normally involves writing code that most teachers are not comfortable with (see http://webwork.maa.org/wiki/SampleProblem1). So then, it's just a simple form (using form_tag, I believe), and I grab all of the request parameters at the top of the script. The question, answer and answer_explanation all need to be run through a method that parses the wml (as I'm calling it) into Perl/Tex code appropriate for the problem, for instance, from ==3/5== to \(frac{3}{5}\). As you can see, it's currently only those three fields that I need to parse; I don't want to use extra resources running everything through parsing. In the future, though, I see a larger number of fields that need to be parsed, which is what I'm trying to write for. Currently none of this is in any sort of model (since it's not going in a database, I thought it shouldn't be), but I'm thinking that perhaps that would be a better way of doing things, and may simplify this whole thing. Unfortunately, I'm not familiar enough with models to know if it's something I should spend my time figuring out; if it is, I'm glad to struggle through getting it to work, but I have other things to fix if that won't be worthwhile. So, the short of it is, that site is what I'm doing, for the most part. And apologies if I seem a little on edge; while I've found the ruby community to be quite helpful, I miss my PHP manual, with all of its user comments that are ever-so-helpful. The more popular a language, the easier it is to find things on it, so a popular language can be easier to learn than a less popular one, even if the less popular actually has a more gentle learning curve. -- Posted via http://www.ruby-forum.com/.