What's the point of the “/” after defining something in webfocus? - webfocus

I'm currently learning webfocus and I'm learning about defining, but what is teaching me isn't doing a great job. An example that has been given to me is about cars. If I want to make a new field to find the difference between the retail cost and the dealer cost, they said to input
What I'm confused about is what the
is there for. Is it required to define a file? Does it have to be something specific? I've researched a lot but haven't found any answers about it.

From what I understand, it joins the aliases and roots. For example the D could be short for difference. The 5 could just be a number. Without all of the example and question it's hard to say.
Here is another example http://www.hwconline.com/ibi_html/javaassist/intl/EN/help/source/topic547.htm
A preceding forward slash '/' is required for all aliases and context roots. The WebFOCUS Administration Console automatically adds a forward slash if one was not entered.
I am assuming it could be a pointer. Look at the url and the / indicates like a tree node. If you want to get to a location then it's location/location/location/here
here being what your looking at. So if the /D5 is called it could mean page/page/page/Difference5 so for short it omits all of the pages and signifies the direct alias D5.
I am not entirely sure but that is what I have always thought. Look at everything dealing with locations a \ or / is always used.

I've found out what it means. The /D5 is known as formatting. It allows WebFOCUS to know what is being used in the file. The D stands for decimal, which means that if I wanted to I could format it as D/5.2 and an A stands for alphanumeric. If I were to define a file called person_last_name, I would use A/30. The number determines how much data it can hold, so 30 is all I need as a person's last name probably won't be longer than 30 characters.


Input on JavaScript i18n implementation needed

I'm devising an i18n helper for JavaScript and would like some input on the implementation.
In the basic scenario it should provide some sort of lookup functionality based on a locale object: (with support for variables)
var locales = {
en : {
pages : {
myPage1 : {
title : "A title with <em>highlighted %s</em>",
function _(path) {
//lookup and return translation
_(pages.myPage1.title, "text") => "A title with <em>highlighted text</em>"
Later, I'd like to implement support for plural/singular etc:
var locales = {
en : {
pages : {
myPage1 : {
title : "A title with <em>%s text</em>",
tickets : {
_0 : "0 tickets left",
_1 : "1 ticket left",
_1+ : "%s tickets left"
function _n(path, count) {
//lookup and return translation
_n(pages.myPage1.ticketsLeft,5) => "5 tickets left"
... And also integrate this with a templating engine:
<h1>{{ _(pages.myPage1.title) }}</h1>
<p>{{ _n(pages.myPage1.ticketsLeft, {{ variable }} ) }}</p>
What pitfalls are there in basic i18n and what does the implementation above lack that should be considered from the beginning?
How would you code the actual methods _(), _n() so that they work with an object as the one given?
Any ideas on the template integration - how should it be done?
Are there any "translation crowd-sourcing services" that work well together with JavaScript?
Ad 1. Your assumption on just one plural form is wrong. Some languages have few different plural forms (Polish translation of your example):
one: Pozostał jeden bilet.
few: Pozostały 2 bilety.
many: Pozostało 5 biletów.
other: Pozostało 1,5 biletu. // OK, this one doesn't make sense but that's how it would be translated if it does...
Please find more information in CLDR. Notice plural forms for Arabic.
Ad 2. For translating, I would use Globalize since it has this functionality more or less built-in (there is a Localize() function). The only problem from my observation would be Locale fall-back. You actually need to ensure that something like de-AT (German/Austria) fall back to de (German/country invariant) unless you have specific translations for given language. The Chinese might be bigger problem, you should not under any circumstances fall back to Chinese Simplified (if zh points to it), if you have Chinese Traditional Locale. Using zh-Hans and zh-Hant might be a good idea.
As for plural forms, you probably need to incorporate the data from CLDR chart above and use some logic based on Locale. I would probably extend Globalize's culture files by adding plural forms and then by calling FindClosestCulture() (if I recall it correctly) I would check what sort of rule should I use for this context (Locale and number). Then reading appropriate message with Localize(). Of course one would need to write messages with appropriate keys, like:
tickets-one : One ticket left.
tickets-other: : {0} tickets left.
BTW. I would use numbered placeholders. The reason is, sometimes you need to place more than one. In that case if you have two exactly the same %s placeholders, translators won't be able to re-order the sentence. And that is required more often than you think (many languages have totally different grammar rules than English).
Ad 3. Depending on your templating engine...
Ad 4. That depends on how you want to integrate this. Usually, server-side translation is used, so you actually write out JavaScript file from your application back-end. In that case depending on technology you are using in your back-end, you might use simple properties files or more complicated (but often better) solutions like Gettext. For both formats you can easily find crowdsourcing platform (i.e. Launchpad supports the latter out of the box). If you want someone to translate your JavaScript files like the one you are showing above, that's actually not very good idea. One problem with it, it is non-standard so many people won't actually know how to translate it. Another, it is very easy to actually damage it by forgetting to add a comma, the colon or curly brace. These are the errors you (or some unfortunate soul using what you have written) would have to deal with.
In addition to the plural form issue that Paweł Dyda described, there are a few other potential problems:
The writing of the number may need localization, partly because the format of large numbers varies (e.g., 1 234 vs. 1,234 vs. 1’234 vs. something else), partly because different digit characters may be needed. The Globalize.js library solves the first issue, the digit issue may need separate coding.
In the case of 0 items, it might be more natural to use the equivalent of “No” than the digit zero, in the text shown to the user.
The use of markup like is problematic, as it is normally rendered in italics, and italics makes no sense for many writing systems. You may need to use language-specific style sheets to modify the rendering of . This is as such external to JavaScript, but to make it possible, make sure that the markup you generate either contains the lang attribute (so that stylesheets can apply different rules per language) or refers to language-specific stylesheets.
The localize() method in Globalize.js is very simple, suitable for the case of a set of string literals to be localized (translated). But you can write your own, more advanced code so that you add properties to the culture objects there.
Overall, much depends on the intended scope: how many languages (and what types of languages) are you going to cover, and what kinds of localization different from simple string localization will you need? Implementing a general scheme for handling expressions of the type “n items” is not simple—CLDR gives you sets of rules, but you would need to code them, and in translations, you would need to request for all the relevant inclined forms of a noun like “item.” If such expressions occur in some specific context(s) only, it might be feasible to reformulate things so that you don’t say “n tickets left” but “Number of tickets left: n.” This would be much easier to implement: just string localization and number localization.

A different way to write the element ID? [closed]

Below I have this one line of javascript. I want to know if there is another way I can write the name-id tag (the element ID). So is there a different way I can write it, would would mean the same thing? Example in ASCII form?
I know in C I could write this in ASCII form.
var myname = document.getElementById("name-id").innerHTML;
You can find technical details of character encoding in current implementation of JavaScript in the official ECMAScript documentation.
ECMAScript code is expressed using Unicode, version 8.0.0 or later. ECMAScript source text is a sequence of code points. All Unicode code point values from U+0000 to U+10FFFF, including surrogate code points, may occur in source text where permitted by the ECMAScript grammars.
If less interested in technical aspects and in need of an obfuscator service, just use any of them or compare them. With minimal effort, you can produce something like this:
var _0x2245=['innerHTML','querySelector'],x="tell_me_a_nice_story"
_0x2245,4e3);var _0x1144=function(x0,x0x0){return _0x2245[x0-=0]},
myname=document[_0x1144("0x0")]( _0x1144("0x1"))[_0x2245[+2e0+0]];
<div id="name-id"
>Why would you do this?
If you really want to make it hard for others to read name-id in your code, you can do a whole bunch of stuff on it.
You could write something completely different that contains all needed chars or all but one, which you'll add later, split that string into an array using some other unused letter as delimiter, take some array elements from their current position and place them at some other position, join a few, delete others and invert the value of others. Get creative.
By the end of second line above i have innerHTML, querySelector and #name-id as members of the same array. Only name-id was mambo-jambo-ed from tell_me_a_nice_story but I could have easily produced innerHTML and querySelector from a slightly longer text, provided it contained most of the required letters. Think of it as a round of Scrabble.
The last line of the "code block" could be replaced with any of the following:
or countless other variants, which "kind of" answer your question and fit the number of chars: 66.
But, let's be very clear about it: anyone decent in JavaScript will have no problem debugging your code or console.log()-ing the result of your final step, to get the value in a matter of seconds.
In all fairness, you can't really hide anything in JavaScript (frontend) without a server (to run a proper encryption service).
Element IDs automatically become properties in the global window object, so you can write:
var myname = window['name-id'].innerHTML;
And since window properties are global variables, you can also access it as a variable, but only if the ID is a valid identifier. Since - is not allowed in an identifier name, you can't do this with name-id. But if you had:
var myname = document.getElementById("someid").innerHTML;
you could write it as:
var myname = someid.innerHTML;
However, I don't really recommend this, I'm just showing it for demonstration purposes. If the element ID is the same as a standard window property (e.g. location or document), the standard property takes precedence.
See Do DOM tree elements with ids become global variables?

Replacement of “-' with ”_" using a loop in javascript

I have applied the same method to replace "-" with "_" in c++ and it is working properly but in javascript, it is not replacing at all.
function replace(str)
for(var i=0;i<str.length;i++)
str.charAt(i) = "_";
return str;
It's simple enough in javascript, it's not really worth making a new function:
function replace(str){
return str.replace(/-/g, '_') // uses regular expression with 'g' flag for 'global'
This does not alter the original string, however, because strings in javascript are immutable.
If you are dead set on avoiding the builtin(maybe you want to do more complex processing), reduce() can be useful:
function replace(str){
return [...str].reduce((s, letter) => s += letter == '-' ? '_' : letter , '')
You can easily replace complete string using .split() and .join().
function replace(str){
return str.split("-").join("_");
This is yet another case of "make sure you read the error message". In the case of
str.charAt(i) = "_";
the correct description of what happens is not "it is not replacing at all", as you would have it; it is "it generates a run-time JavaScript error", which in Chrome is worded as
Uncaught ReferenceError: Invalid left-hand side in assignment
In Firefox, it is
ReferenceError: invalid assignment left-hand side
That should have given you the clue you needed to track down your problem.
I repeat: read error messages closely. Then read them again, and again. In the great majority of cases, they tell you exactly what the problem is (if you only take the time to try to understand them), or at least point you in right direction.
Of course, reading the error message assumes you know how to view the error message. Do you? In most browsers, a development tools window is available--often via F12--which contains a "console", displaying error messages. If you don't know about devtools, or the console, then make sure you understand them before you write a single line of code.
Or, you could have simply searched on Stack Overflow, since (almost) all questions have already been asked there, especially those from newcomers. For example, I searched in Google for
can i use charat in javascript to replace a character in a string?
and the first result was How do I replace a character at a particular index in JavaScript?, which has over 400 upvotes, as does the first and accepted answer, which reads:
In JavaScript, strings are immutable, which means the best you can do is create a new string with the changed content, and assign the variable to point to it.
As you learn to program, or learn a new languages, you will inevitably run into things you don't know, or things that confuse you. What to do? Posting to Stack Overflow is almost always the worst alternative. After all, as you know, it's not a tutorial site, and it's not a help site, and it's not a forum. It's a Q&A site for interesting programming questions.
In the best case, you'll get snarky comments and answers which will ruin your day; in the worst case, you'll get down-voted, and close-voted, which is not just embarrassing, but may actually prevent you from asking questions in the future. Since you want to make sure you are able to ask questions when you really need to, you are best off taking much more time doing research, including Google and SO searches, on simple beginner questions before posting. Or find a forum which is designed to help new folks. Or ask the person next to you if there is one. Or run through one or more tutorials.
But why write it yourself at all?
However, unless you are working on this problem as a way of teaching yourself JavaScript, as a kind of training exercise, there is no reason to write it at all. It has already been written hundreds, or probably thousands, of times in the history of computing. And the overwhelming majority of those implementations are going to be better, faster, cleaner, less buggy, and more featureful than whatever you will write. So your job as a "programmer" is not to write something that converts dashes to underscores; it's to find and use something that does.
As the wise man said, today we don't write algorithms any more; we string together API calls. Our job is to find, and understand, the APIs to call.
Finding the API is not at all hard with Google. In this case, it could be helpful if you knew that strings with underscores are sometimes called "snake-cased", but even without knowing that you can find something on the first page of Google results with a query such as "javascript convert string to use underscores library".
The very first result, and the one you should take a look at, is underscore.string, a collection of string utilities written in the spirit of the versatile "underscore" library, and designed to be used with it. It provides an API called underscored. In addition to dealing with "dasherized" input (your case), it also handles other string/identifier formats such as "camelCase".
Even if you don't want to import this particular library and use it (which you probably should), you would be much better off stealing or cloning its code, which in simplified form is:
.replace(/([a-z\d])([A-Z]+)/g, '$1_$2')
.replace(/[-\s]+/g, '_')
This is not as complicated as it looks. The first part is to deal with camelCase input, so that "catsAndDogs" becomes "cats-and-dogs". the second line is what handles the dashes and spaces). Look closely--it replaces runs of multiple dashes with a single underscore. That could easily be something that you want to do too, depending on who is doing what with the transformed string downstream. That's a perfect example of something that someone else writing a professional-level library for this task has thought of that you might not when writing your home-grown solution.
Note that this well-regarded, finely-turned library does not use the split/join trick to do global replaces in strings, as another answer suggests. That approach went out of use almost a decade ago.
Besides saving yourself the trouble of writing it yourself, and ending up with better code, if you take time time to understand what it's doing, you will also end up knowing more about regular expressions.

JavaScript code convention - object declaration

I'm developing a JavaScript Style Guide and I'm aware that the only rule that can be applied on code conventions is to be consistent but I'm curious about this question since none of the major frameworks use this convention.
What are the advantages and disadvantages of vertical align the colons/equals when declaring objects/variables?
var a = 1,
ab = 2,
abc = 3;
var obj = {
a : 1,
ab : 2,
abc : 3
Better code readability. That's about it.
Disadvantage is when using find to find the value of a variable as there are more spaces than required. So a search for variablename = may result in nothing due to it actually being defined as variablename[space][space][space]=.
Searching in the code would be one obvious disadvantage:
Imagine that I inherited your system, or must work on it. In the progress, I need to figure out what the a variable is. The system has a huge codebase with lots of lines, so simply scrolling through and looking at every line is not an option.
If the code standard was variable = 123, then I could simply do a "search-in-files" for variable[SPACE]=[SPACE].
This is where the standard you posted might be a bad idea. I don't know how many spaces are going to between the variable name and your equal sign. Of course I could search for a[SPACE]=, a[SPACE][SPACE]=, a[SPACE][SPACE][SPACE]= etc., but it'd be a lot harder.
The only way to search for the declarations (in a raw code editor with no "find declaration" helper), would be to do a Regex search for variable\s+= (one or more spaces) or variable\s*= (zero or more spaces), which will take longer and requires an editor with Regex search capabilities.
Putting each variable on a separate line will benefit you when you go to read it again (or someone else reads it) because it will be clear that these are different variables, so increased readability is the main factor.
It mainly is a benefit in the long term when it comes down to passing the code to another programmer to maintain or modify something or if you come back to it after a long period of time and can't remember the code.
It is the same in most languages.
Also aligning the variables with eachother (and the values) can make the code look very neat and tidy but it is a lot of hassle to do and most people don't do this. You would align the start of the line but not anything else afterwards.
Imagine what would happen if something changed and you had to realign everything.
NOT GOOD. Waste of time which could be spent programming.

How to define /#-like operator

I would like to define a new operator of the form x /==> y, where
the operator /==> is treated as e.g. the /# operator of Map, and
is translated to MyFunction[x, y]. There is one important aspect: I
want the resulting operator to behave in the frontend like any two-bit
operator does, that is, the two characters (a Divide and a
DoubleLongRightArrow) should be connected together, no syntax
coloration should appear, and they are to be selected together when
clicked, so precedence must be set. Also, I'd rather avoid using the
Notation` package. As a result, I'd like to see something like this:
In[11]:= FullForm[x/\[DoubleLongRightArrow]y]
Out[11]//FullForm= MyFunction[x,y]
Does anyone have an idea how to achieve this?
The Notation Package is perhaps the closest to doing this kind of thing, but according to the response to my own question of a similar nature, what you want is unfortunately not practical.
Don't let this stop you from trying however, as you will probably learn new things in the process. The Notation Package and the the functions that underpin it are far from useless.
You may also find the replies to this question informative.
There are a number of functions that are useful for manual implementation of syntax changes. Rather than try to write my own help file for these, I will direct you to the official pages on these functions. After reading them, please ask any focused questions you have, or for help with implementing specific ideas. I or others here should be able to either answer your question, show you how to do something, or explain why it is not readily possible.
The index page on Textual Input and Output.
MakeBoxes, and MakeExpression, and an example of their use.
More drastically, one might use CellEvaluationFunction which can be used to do unusual things.
There are more, and I will try to extend this list later. (others are welcome to edit this post)
Thanks to Mr.Wizard's links, I've found the only example in the documentation on how to parse new operators (the gplus example in Low-Level Input). According to this example, here is my version for the new operator PerArrow. Please comment/critize on the code below:
In[1]:= PerArrow /: MakeBoxes[PerArrow[x_, y_], StandardForm] :=
RowBox[{MakeBoxes[x, StandardForm],
RowBox[{AdjustmentBox["/", BoxMargins -> -.2],
AdjustmentBox["\[DoubleLongRightArrow]", BoxMargins -> -.1]}],
MakeBoxes[y, StandardForm]}];
RowBox[{x_, "/", RowBox[{"\[DoubleLongRightArrow]", y_}]}],
StandardForm] :=
MakeExpression[RowBox[{"PerArrow", "[", x, ",", y, "]"}],
In[3]:= PerArrow[x, y]
Out[3]= x /\[DoubleLongRightArrow] y
In[4]:= x /\[DoubleLongRightArrow]y
Out[4]= x /\[DoubleLongRightArrow] y
In[5]:= FullForm[x /\[DoubleLongRightArrow]y]
Out[5]//FullForm= \!\(\*
RowBox[{"PerArrow", "[",
RowBox[{"x", ",", "y"}], "]"}],
For sake of clarity, here is a screenshot as well:
Since the operator is not fully integrated, further concerns are:
the operator is selected weird when clicked (DoubleLongRightArrow with y instead of with /).
accordingly, the parsing part requires the DoubleLongRightArrow to be RowBox-ed with y, otherwise it yields syntax error
syntax coloration (at In[4] and In[5])
it prints weird if inputted directly (notice the large gaps at In[4] and In[5])
Now, I can live with these, though it would be nice to have some means to iron out all the minor issues. I guess all these boil down to basically some even lower-level syntax handler, which does not now how to group the new operator. Any idea on how to tackle these? I understand that Cell has a multitude of options which might come handy (like CellEvaluationFunction, ShowAutoStyles and InputAutoReplacements) though I'm again clueless here.