I have Googled ASP Classic implementations of the natural sort algorithm to no avail. Best I was able to find was from Dave Koelle, which was from a question on SO. Issue is that since I need to implement this algorithm in ASP Classic, I don't have access to certain functions such as
Collections.sort(your list, new AlphanumComparator());
Ideally, I'd like to pass an array to a function and have it return to me the ordered array.
Any ideas as to what I could do?
Thank you.
You haven't specified which language you are using in ASP. Typically this would be VBScript.
However if you were to use JScript instead then you can use JScript's array object and use its sort method. This method optionally takes as a parameter a comparator function.
var a = new Array();
// code to populate array
a.sort(function() { // Comparator code returning (-1|0|1) });
There is no need to convert everything to JScript, you can use utilities written in JScript from VBScript.
Related
lets say, that I have a form with Image field and function ```getImageWidth()```, that checks Image width. After some time, I am adding a new Mobile Image field to my form and I am wondering, what is the best practice for writing a function to check Mobile Image width - extend the old one function ```getImageWidth()``` (by adding parameter isMobileImage) or writing a new ```getMobileImageWidth()``` function? The code for this new function is almost similar to the old one.
What are your opinions?
Thank you,
I think, that getMobileImageWidth() will be better option. For example there is topic Remove Flag Argument in Martin Fowler's blog. And in his book Refactoring: Improving the Design of Existing Code he wrote the next statement:
I dislike flag arguments because they complicate the process of understanding what
function calls are available and how to call them. My first route into an API is usually
the list of available functions, and flag arguments hide the differences in the function
calls that are available. Once I select a function, I have to figure out what values are
available for the flag arguments. Boolean flags are even worse since they don’t convey
their meaning to the reader—in a function call, I can’t figure out what true means. It’s
clearer to provide an explicit function for the task I want to do.
I think it is exactly what you need.
I'm trying to call the random function inside another function. For example I want to do this assert(fact(random()). But it does not work. How can I insert a random number this way? Thanks.
In prolog there is no concept of functions like you are trying to do in your code. You should do:
random(N), assert(fact(N))
I recommend reading at least first two chapters Learn Prolog Now! to better understand search and unification.
I'm looking for a way to define queries on sets independently from a programming language or the kind of sets.
In detail this would be a language definition and implementations for common languages like Java, C++, Python etc.
As commented I'm not looking for a database or any implementation of a set-representation but only a way to define a query for elements from e.g. a std::set/vector a Python set() or any linear structure which can be seen as a set.
A close example would be something like jLinq but without being tied to JSON or javascript and with a well defined string representation.
Of course without knowing the kind of data structure you would have to implement any conditional filter for every problem and every programming language, but the way you construct query strings and how you evaluate them would be clear and you would not have to write parsers.
So what I'd like to write in Java or C++ is something like
q = query()
.created_after("14.03.2010")
.and(contains("hello")
.or(contains("hallo")))
.sort("caption")
or written as a string:
"(created_after("14.03.2010") and ( contains("hello") or contains("hallo"))) sort("caption")"
(this is not thought through - just to show what an interface could look like)
A good example for a different problem would be JSON or XML: clear language definition and parsers/tools for any platform or programming language.
I know this is an old question, but I think I know what you mean and I was actually looking for something similar. What you need is a "search query parser".
I found search-query-parser for nodejs (I'm not the author). Haven't tried it yet but looks promising.The example in the docs is very illustraring, you would receive an input string from the UI
from:hi#retrace.io,foo#gmail.com to:me subject:vacations date:1/10/2013-15/04/2014 photos
And the library would parse it to a structured json object
{
from: ['hi#retrace.io', 'foo#gmail.com'],
to: 'me',
subject: 'vacations',
date: {
from: '1/10/2013',
to: '15/04/2014'
},
text: 'photos'
}
And the from that object you could construct and issue a query command to your database. As you can see it handles lists and ranges. Right away I can't see any boolean operator (AND,OR) but I guess could be easily implemented.
Hope this helps.
RSQL is a good option these days. There are plenty of parsers available and the queries are URL friendly.
LVM_SORTITEMS requires a pointer to an application defined comparison function but I was wondering instead of that where I could find the function explorer uses so to use that instead?
The function is application specific and Explorer provides a pointer to its own code. You cannot reuse it and even analyze it in any better way than hooking, breaking with debugger and studying disassembly.
A typical function would take item specific value, which for example, could be a pointer to some internal structure, and then compare the values from structures of the two items in question. You clicked on "Size" column, then the function would look up size for item #1 and size for item #2 and return the comparison result.
The fact that it's related to internal structures makes you unable to reuse that function the way you supposedly wanted to.
Was there any built-in sort function to sort an array (of string or of integer) in freepascal?
In c/c++ there is std::sort(any_arr) or qsort(any_arr) that can do this..
In Javascript or ruby there is .sort method..
What's in object-pascal?
Generic functions is a topic currently in the planning stage. Currently most list types (as benibela said) have own sort and customsort options.
Some of the generic container types (like tfpsmap in unit fgl) might have generic sort routines, but usually work with a separate compare function pointer/variable to determine order.